PMU-PIbd-32-Fedorenko-G-Y/flutter_app/lib/main.dart
2024-10-03 11:45:55 +04:00

67 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import 'models/album.dart';
import 'repositories/album_repository.dart';
import 'services/album_service.dart';
import 'widgets/album_card.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Music Reviewer',
theme: ThemeData.dark().copyWith(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.purpleAccent)
),
home: const MyHomePage(title: 'Music Reviewer'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final AlbumRepository _albumRepository = AlbumRepository();
List<Album> _albums = [];
@override
void initState() {
super.initState();
_loadAlbums();
}
Future<void> _loadAlbums() async {
_albums = await fetchAlbums();
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: ListView.builder(
itemCount: _albums.length,
itemBuilder: (context, index) {
final album = _albums[index];
return AlbumCard(album: album);
},
),
);
}
}