From d61899dd5e8ac677acd7b1182f70a1995cbd1c30 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Thu, 24 Mar 2022 09:57:47 +0100 Subject: [PATCH] Add player buttons --- lib/main.dart | 96 +-------------------------------------- lib/ui/music_player.dart | 44 +++++++++++++++++- lib/ui/player_app.dart | 97 ++++++++++++++++++++++++++++++++++++++++ test/widget_test.dart | 3 +- 4 files changed, 141 insertions(+), 99 deletions(-) create mode 100644 lib/ui/player_app.dart diff --git a/lib/main.dart b/lib/main.dart index 9d87a91..03d475d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,102 +1,8 @@ -// 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/config.dart'; -import 'package:music_web_player/ui/music_player.dart'; +import 'package:music_web_player/ui/player_app.dart'; void main() { loadConfig(); runApp(const PlayerApp()); } - -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(), - ), - ); - } -} - -class AppHome extends StatefulWidget { - const AppHome({Key? key}) : super(key: key); - - @override - State createState() => _AppHomeState(); -} - -class _AppHomeState extends State { - var error = false; - List? musics; - - Future 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!); - } -} diff --git a/lib/ui/music_player.dart b/lib/ui/music_player.dart index 2683d2e..01c164e 100644 --- a/lib/ui/music_player.dart +++ b/lib/ui/music_player.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'dart:ui'; +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'; @@ -67,9 +68,12 @@ class _MusicPlayerState extends State { } Widget _buildCenter() { - return Center( - child: IntrinsicHeight( + return fluent.Center( + child: Container( + width: 250, child: Column( + mainAxisAlignment: fluent.MainAxisAlignment.center, + crossAxisAlignment: fluent.CrossAxisAlignment.center, children: [ Material( borderRadius: const BorderRadius.all( @@ -89,9 +93,45 @@ class _MusicPlayerState extends State { Text(currMusic.title, style: const TextStyle(fontSize: 22)), const SizedBox(height: 20), Text(currMusic.artist), + const fluent.SizedBox(height: 40), + fluent.Slider( + max: 100, + value: 10, + onChanged: (v) => {}, + // Label is the text displayed above the slider when the user is interacting with it. + label: 'hey', + ), + const fluent.SizedBox(height: 40), + fluent.Row( + children: [ + IconButton( + icon: const PlayerIcon(fluent.FluentIcons.previous), + onPressed: () => {}, + ), + const Spacer(), + IconButton( + icon: const PlayerIcon(fluent.FluentIcons.play), + onPressed: () => {}, + ), + const Spacer(), + IconButton( + icon: const PlayerIcon(fluent.FluentIcons.next), + onPressed: () => {}, + ), + ], + ) ], ), ), ); } } + +class PlayerIcon extends StatelessWidget { + final IconData icon; + + const PlayerIcon(this.icon, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) => Icon(icon, size: 35); +} diff --git a/lib/ui/player_app.dart b/lib/ui/player_app.dart new file mode 100644 index 0000000..a6d6602 --- /dev/null +++ b/lib/ui/player_app.dart @@ -0,0 +1,97 @@ +// 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( + iconTheme: const IconThemeData(color: Colors.white)), + ), + ); + } +} + +class AppHome extends StatefulWidget { + const AppHome({Key? key}) : super(key: key); + + @override + State createState() => _AppHomeState(); +} + +class _AppHomeState extends State { + var error = false; + List? musics; + + Future 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!); + } +} diff --git a/test/widget_test.dart b/test/widget_test.dart index 0c92df5..4886f78 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -7,8 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; - -import 'package:music_web_player/main.dart'; +import 'package:music_web_player/ui/player_app.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async {