MusicPlayer/lib/ui/player_app.dart

100 lines
2.4 KiB
Dart
Raw Normal View History

2022-03-24 08:57:47 +00:00
// ignore_for_file: avoid_print
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:music_web_player/api.dart';
import 'package:music_web_player/ui/music_player.dart';
class PlayerApp extends StatelessWidget {
const PlayerApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Music player',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.green,
brightness: Brightness.dark,
),
home: fluent.FluentTheme(
child: const AppHome(),
data: fluent.ThemeData(
2022-03-24 13:55:41 +00:00
iconTheme: const IconThemeData(color: Colors.white),
brightness: fluent.Brightness.dark,
),
2022-03-24 08:57:47 +00:00
),
);
}
}
class AppHome extends StatefulWidget {
const AppHome({Key? key}) : super(key: key);
@override
State<AppHome> createState() => _AppHomeState();
}
class _AppHomeState extends State<AppHome> {
var error = false;
List<MusicEntry>? musics;
Future<void> load() async {
try {
setState(() => error = false);
musics = await API.getList();
setState(() {});
} catch (e, s) {
print("$e $s");
setState(() => error = true);
}
}
@override
void initState() {
super.initState();
load();
}
@override
Widget build(BuildContext context) {
return Scaffold(body: buildBody(context));
}
Widget buildBody(BuildContext context) {
if (error) {
return Center(
child: IntrinsicHeight(
child: Column(
children: [
const Icon(
FluentIcons.warning_24_regular,
size: 50,
color: Colors.white,
),
const SizedBox(height: 50),
const Text("Failed to load musics list!"),
const SizedBox(height: 50),
fluent.FilledButton(
onPressed: load,
child: Text("Try again".toUpperCase()),
),
],
),
));
}
if (musics == null) {
return const Center(child: fluent.ProgressRing());
}
if (musics!.isEmpty) {
return const Center(child: Text("Musics list is empty!"));
}
return MusicPlayer(musicsList: musics!);
}
}