From 02f3a5d6df163d291914a2df4a2406ba3c69dd00 Mon Sep 17 00:00:00 2001 From: Ashwin Ramakrishnan Date: Thu, 18 Mar 2021 17:57:01 +0530 Subject: [PATCH] fix: Null safe future calls Signed-off-by: Ashwin Ramakrishnan --- lib/provider/song_widget.dart | 28 +--- lib/provider/theme.dart | 2 +- lib/view/home_scaffold.dart | 5 +- lib/view/playback_controls.dart | 264 +++++++++++++++++--------------- lib/widgets/my_music_list.dart | 2 +- lib/widgets/seekbar.dart | 8 +- 6 files changed, 156 insertions(+), 153 deletions(-) diff --git a/lib/provider/song_widget.dart b/lib/provider/song_widget.dart index d53edfc..6923ca5 100644 --- a/lib/provider/song_widget.dart +++ b/lib/provider/song_widget.dart @@ -3,7 +3,6 @@ import 'package:provider/provider.dart'; import 'package:raag/model/music_model.dart'; import 'package:raag/provider/player_provider.dart'; import 'package:raag/provider/theme.dart'; -import 'package:raag/view/playback_controls.dart'; import 'audio_helper.dart'; @@ -16,23 +15,9 @@ class SongWidget extends StatefulWidget { _SongWidgetState createState() => _SongWidgetState(); } -class _SongWidgetState extends State with TickerProviderStateMixin { - @override - void initState() { - super.initState(); - playFABController = - AnimationController(vsync: this, duration: Duration(milliseconds: 300)); - } - - @override - void dispose() { - super.dispose(); - playFABController.dispose(); - } - +class _SongWidgetState extends State { @override Widget build(BuildContext context) { - final screenHeight = MediaQuery.of(context).size.height; final screenWidth = MediaQuery.of(context).size.width; final provider = Provider.of(context); @@ -40,9 +25,9 @@ class _SongWidgetState extends State with TickerProviderStateMixin { children: [ Flexible( child: ListView.builder( - itemCount: widget.songList.length, + itemCount: widget?.songList?.length, itemBuilder: (context, songIndex) { - Song song = widget.songList[songIndex]; + Song song = widget?.songList[songIndex]; if (song.displayName.contains(".mp3")) return Column( children: [ @@ -50,9 +35,9 @@ class _SongWidgetState extends State with TickerProviderStateMixin { Container( padding: EdgeInsets.symmetric(horizontal: 8), decoration: BoxDecoration( - color: Theme.of(context).dividerColor.withOpacity(0.4), - borderRadius: BorderRadius.all(Radius.circular(24)) - ), + color: Theme.of(context).dividerColor, + borderRadius: + BorderRadius.all(Radius.circular(24))), child: InkWell( onTap: () { if (provider.audioManagerInstance.isPlaying) @@ -121,7 +106,6 @@ class _SongWidgetState extends State with TickerProviderStateMixin { ); }), ), - PlayBackControls(), ], ); } diff --git a/lib/provider/theme.dart b/lib/provider/theme.dart index bdee2be..bc5e1e0 100644 --- a/lib/provider/theme.dart +++ b/lib/provider/theme.dart @@ -77,7 +77,7 @@ class AppTheme { static final ThemeData darkTheme = ThemeData( backgroundColor: hex('000000'), accentColor: hex('809DF5'), - dividerColor: hex('404040'), + dividerColor: hex('1a1a1a'), scaffoldBackgroundColor: hex('000000'), appBarTheme: AppBarTheme( color: hex('000000'), diff --git a/lib/view/home_scaffold.dart b/lib/view/home_scaffold.dart index 5b96332..aeac0cc 100644 --- a/lib/view/home_scaffold.dart +++ b/lib/view/home_scaffold.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:raag/provider/settings_provider.dart'; +import 'package:raag/view/download_music.dart'; +import 'package:raag/view/playback_controls.dart'; import 'package:raag/view/settings.dart'; import 'package:raag/widgets/my_music_list.dart'; -import 'package:raag/view/download_music.dart'; class HomeScaffold extends StatelessWidget { @override @@ -57,6 +59,7 @@ class HomeScaffold extends StatelessWidget { children: [MyMusicList()], ), ), + PlayBackControls() ], ), ); diff --git a/lib/view/playback_controls.dart b/lib/view/playback_controls.dart index 410148d..65a2ac0 100644 --- a/lib/view/playback_controls.dart +++ b/lib/view/playback_controls.dart @@ -1,3 +1,5 @@ +import 'dart:ui'; + import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:raag/provider/audio_helper.dart'; @@ -9,145 +11,155 @@ class PlayBackControls extends StatefulWidget { _PlayBackControlsState createState() => _PlayBackControlsState(); } -class _PlayBackControlsState extends State { +class _PlayBackControlsState extends State + with TickerProviderStateMixin { + @override + void initState() { + super.initState(); + playFABController = + AnimationController(vsync: this, duration: Duration(milliseconds: 300)); + } + + @override + void dispose() { + super.dispose(); + playFABController.dispose(); + } + @override Widget build(BuildContext context) { - var glowShadow = BoxShadow( - color: Theme.of(context).accentColor.withOpacity(0.3), - spreadRadius: 5, - blurRadius: 9, - offset: Offset(0, 0), // changes position of shadow - ); final provider = Provider.of(context); return Column( mainAxisAlignment: MainAxisAlignment.end, children: [ - Container( - decoration: BoxDecoration( - boxShadow: [glowShadow], - color: Theme.of(context).backgroundColor, - borderRadius: BorderRadius.only( - topRight: Radius.circular(20), - topLeft: Radius.circular(20), - )), - height: MediaQuery.of(context).size.height * 0.2, - child: Padding( - padding: const EdgeInsets.all(3.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 16), - child: SeekBar(), - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, + ClipRRect( + borderRadius: BorderRadius.only( + topRight: Radius.circular(25), + topLeft: Radius.circular(25), + ), + child: BackdropFilter( + filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), + child: Container( + decoration: BoxDecoration( + color: Theme.of(context).backgroundColor.withOpacity(0.65), + ), + height: MediaQuery.of(context).size.height * 0.2, + child: Padding( + padding: const EdgeInsets.all(3.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - SizedBox( - width: 70, + Padding( + padding: EdgeInsets.symmetric(horizontal: 16), + child: SeekBar(), ), - new Container( - height: 50, - width: 50, - decoration: new BoxDecoration( - shape: BoxShape.circle, - border: new Border.all( - color: Theme.of(context).dividerColor, - width: 2.5, + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: 70, ), - ), - child: new Center( - child: RawMaterialButton( - shape: CircleBorder(), - child: Icon( - Icons.skip_previous_outlined, - color: Theme.of(context).accentColor, - size: 30, + new Container( + height: 50, + width: 50, + decoration: new BoxDecoration( + shape: BoxShape.circle, + border: new Border.all( + color: Theme.of(context).dividerColor, + width: 2.5, ), - elevation: 0, - onPressed: () { - provider.audioManagerInstance.previous(); - }), - ), - ), - SizedBox( - width: 10, - ), - new Container( - height: 70, - width: 70, - decoration: new BoxDecoration( - shape: BoxShape.circle, - border: new Border.all( - color: Theme.of(context).dividerColor, - width: 2.5, + ), + child: new Center( + child: RawMaterialButton( + shape: CircleBorder(), + child: Icon( + Icons.skip_previous_outlined, + color: Theme.of(context).accentColor, + size: 30, + ), + elevation: 0, + onPressed: () { + provider.audioManagerInstance.previous(); + }), + ), ), - ), - child: RawMaterialButton( - shape: CircleBorder(), - child: Center( - child: AnimatedIcon( - color: Theme.of(context).accentColor, - icon: AnimatedIcons.play_pause, - size: 50, - progress: playFABController, + SizedBox( + width: 10, + ), + new Container( + height: 70, + width: 70, + decoration: new BoxDecoration( + shape: BoxShape.circle, + border: new Border.all( + color: Theme.of(context).dividerColor, + width: 2.5, ), ), - elevation: 0, - onPressed: () { - if (provider.audioManagerInstance.isPlaying) { - playFABController.reverse(); - provider.playerState = PlayerState.paused; - } - else { - playFABController.forward(); - provider.playerState = PlayerState.playing; - } - provider.audioManagerInstance.playOrPause(); - }), - ), - SizedBox( - width: 10, - ), - new Container( - height: 50, - width: 50, - decoration: new BoxDecoration( - shape: BoxShape.circle, - border: new Border.all( - color: Theme.of(context).dividerColor, - width: 2.5, + child: RawMaterialButton( + shape: CircleBorder(), + child: Center( + child: AnimatedIcon( + color: Theme.of(context).accentColor, + icon: AnimatedIcons.play_pause, + size: 50, + progress: playFABController, + ), + ), + elevation: 0, + onPressed: () { + if (provider.audioManagerInstance.isPlaying) { + playFABController.reverse(); + provider.playerState = PlayerState.paused; + } else { + playFABController.forward(); + provider.playerState = PlayerState.playing; + } + provider.audioManagerInstance.playOrPause(); + }), ), - ), - child: new Center( - child: RawMaterialButton( - shape: CircleBorder(), - child: Icon( - Icons.skip_next_outlined, - color: Theme.of(context).accentColor, - size: 30, + SizedBox( + width: 10, + ), + new Container( + height: 50, + width: 50, + decoration: new BoxDecoration( + shape: BoxShape.circle, + border: new Border.all( + color: Theme.of(context).dividerColor, + width: 2.5, ), - elevation: 0, - onPressed: () { - provider.audioManagerInstance.next(); - }), - ), - ), - SizedBox( - width: 35, - ), - new Container( - height: 40, - width: 40, - decoration: new BoxDecoration( - shape: BoxShape.circle, - border: new Border.all( - color: Theme.of(context).dividerColor, - width: 2.5, + ), + child: new Center( + child: RawMaterialButton( + shape: CircleBorder(), + child: Icon( + Icons.skip_next_outlined, + color: Theme.of(context).accentColor, + size: 30, + ), + elevation: 0, + onPressed: () { + provider.audioManagerInstance.next(); + }), + ), ), - ), - child: new Center( - child: RawMaterialButton( + SizedBox( + width: 35, + ), + new Container( + height: 40, + width: 40, + decoration: new BoxDecoration( + shape: BoxShape.circle, + border: new Border.all( + color: Theme.of(context).dividerColor, + width: 2.5, + ), + ), + child: new Center( + child: RawMaterialButton( shape: CircleBorder(), onPressed: () { provider.audioManagerInstance.stop(); @@ -160,14 +172,16 @@ class _PlayBackControlsState extends State { ), elevation: 4, )), + ), + ], ), ], ), - ], + ), ), ), ), ], ); } -} +} \ No newline at end of file diff --git a/lib/widgets/my_music_list.dart b/lib/widgets/my_music_list.dart index 04441cc..cb8e764 100644 --- a/lib/widgets/my_music_list.dart +++ b/lib/widgets/my_music_list.dart @@ -14,7 +14,7 @@ class MyMusicList extends StatelessWidget { future: DBProvider.db.getAllSongs(), builder: (context, snapshot) { List songInfo = snapshot.data; - if (songInfo.isNotEmpty) { + if (songInfo?.isNotEmpty ?? true) { return SongWidget(songList: songInfo); } return LoadingIndicator(); diff --git a/lib/widgets/seekbar.dart b/lib/widgets/seekbar.dart index a8aafd8..b457b0a 100644 --- a/lib/widgets/seekbar.dart +++ b/lib/widgets/seekbar.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:raag/provider/audio_helper.dart'; import 'package:raag/provider/player_provider.dart'; -import 'package:raag/provider/theme.dart'; class SeekBar extends StatefulWidget { @override @@ -17,7 +16,7 @@ class _SeekBarState extends State { children: [ Text( formatDuration(provider.audioManagerInstance.position), - style: durationTheme, + style: Theme.of(context).textTheme.subtitle2, ), Expanded( child: Padding( @@ -60,7 +59,10 @@ class _SeekBarState extends State { ), Text( formatDuration(provider.audioManagerInstance.duration), - style: durationTheme, + style: Theme + .of(context) + .textTheme + .subtitle2, ), ], );