Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
128 views

Source Code

This document contains source code for a music player mobile application written in Dart and Flutter. It includes code for the main app file, a model class to manage the app data, a splash screen class, and classes for the home screen and a "no music found" screen. The app uses a SQLite database to store and retrieve song data, and allows browsing music by albums, artists, playlists and individual songs.

Uploaded by

Sunil Shedge
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Source Code

This document contains source code for a music player mobile application written in Dart and Flutter. It includes code for the main app file, a model class to manage the app data, a splash screen class, and classes for the home screen and a "no music found" screen. The app uses a SQLite database to store and retrieve song data, and allows browsing music by albums, artists, playlists and individual songs.

Uploaded by

Sunil Shedge
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 103

Source code:- 

 
1)main.dart 
 
import 'package:dynamic_theme/dynamic_theme.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/pages/Walkthrough.dart'; 
import 'package:music/sc_model/model.dart'; 
import 'package:scoped_model/scoped_model.dart'; 
 
void main() => runApp(new MyApp()); 
 
class MyApp extends StatelessWidget { 
@override 
Widget build(BuildContext context) { 
return new DynamicTheme( 
defaultBrightness: Brightness.light, 
data: (brightness) => 
new ThemeData( 
primarySwatch: Colors.deepOrange, 
accentColor: Colors.deepOrangeAccent, 
fontFamily: 'Bitter', 
brightness: brightness, 
), 
themedWidgetBuilder: (context, theme) { 
return ScopedModel<SongModel>( 
model: new SongModel(), 
child: new MaterialApp( 
title: 'Music Player', 
theme: theme, 
debugShowCheckedModeBanner: false, 
home: new SplashScreen(), 
), 
); 
}); 


 
2)model.dart 
 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:scoped_model/scoped_model.dart'; 
 
class SongModel extends Model { 
Song _song; 
List<Song> albums, recents, songs; 
Song last; 
Song top; 
int mode = 2; 
 
Song get song => _song; 
 
void updateUI(Song song, db) async { 
_song = song; 
recents = await db.fetchRecentSong(); 
//recents.removeAt(0); 
top = await db.fetchTopSong().then((item) => item[0]); 
notifyListeners(); 

 
void setMode(int mode) { 
this.mode = mode; 
notifyListeners(); 

 
// void updateRecents(db)async{ 
// recents=await db.fetchRecentSong(); 
// recents.removeAt(0); 
// notifyListeners(); 
// } 
init(db) async { 
recents = (await db.fetchRecentSong()); 
recents.removeAt(0); // as it is showing in header 
notifyListeners(); 


 
3)SplashScreen.dart 
 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/musichome.dart'; 
import 'package:music/pages/NoMusicFound.dart'; 
 
class SplashScreen extends StatefulWidget { 
@override 
State<StatefulWidget> createState() { 
return new SplashState(); 


 
class SplashState extends State<SplashScreen>{ 
var db; 
var isLoading = false; 
  
@override 
void initState() {  
super.initState(); 
loadSongs(); 

@override 
void dispose() {  
super.dispose(); 

  
 
@override 
Widget build(BuildContext context) { 
return new Sca old( 
body: SafeArea( 
child: new Container( 
height: MediaQuery.of(context).size.height, 
child: Column( 
mainAxisAlignment: MainAxisAlignment.center, 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
Row( 
mainAxisAlignment: MainAxisAlignment.center, 
children: <Widget>[ 
Image.asset("assets/kids.gif",  
height: 300, width: 300, 
it: BoxFit.cover), 
], 
), 
Container( 
margin: EdgeInsets.only( 
top: MediaQuery.of(context).size.height / 5), 
child: Text( 
"Music player", 
style: TextStyle( 
color: Color(0xFF333945), 
fontSize: 40, 
), 
), 
), 
 
Expanded( 
child: Center( 
child: isLoading ? CircularProgressIndicator( 
backgroundColor: Colors.white, 
) : Container(), 
), 
), 
Text("Setting up...", 
style: TextStyle(color: Color(0xFF333945), fontSize: 20)) 
   
], 
), 
), 
)); 

 
loadSongs() async { 
setState(() { 
isLoading = true; 
}); 
var db = new DatabaseClient(); 
await db.create(); 
if (await db.alreadyLoaded()) { 
Navigator.of(context).pop(); 
Navigator.of(context).push(new MaterialPageRoute(builder: 
(context) { 
return new MusicHome(); 
})); 
} else { 
var songs; 
try { 
songs = await MusicFinder.allSongs(); 
List<Song> list = new List.from(songs); 
 
if (list == null || list.length == 0) { 
// print("List-> $list"); 
Navigator.of(context).pop(true); 
Navigator.of(context).push(new MaterialPageRoute(builder: 
(context) { 
return new NoMusicFound(); 
})); 

else { 
for (Song song in list) 
db.updateInsertSongs(song); 
if (!mounted) { 
return; 

Navigator.of(context).pop(true); 
Navigator.of(context).push(new MaterialPageRoute(builder: 
(context) { 
return new MusicHome(); 
})); 

} catch (e) { 
print("failed to get songs"); 




 
4)NoMusicFound.dart 
 
import 'package:flutter/material.dart'; 
import 'package:flutter/services.dart'; 
import 'package:flutter/widgets.dart'; 
 
class NoMusicFound extends StatelessWidget { 
@override 
Widget build(BuildContext context) { 
return WillPopScope( 
onWillPop: _onWillPop, 
child: new Sca old( 
appBar: AppBar( 
title: Text("Music player"), 
automaticallyImplyLeading: false, 
), 
body: new Center( 
child: SingleChildScrollView( 
child: Column( 
children: <Widget>[ 
Padding( 
padding: const EdgeInsets.all(20.0), 
child: Image.asset( 
"assets/sad.gif", 
height: 200, 
width: 200, 
it: BoxFit.cover, 
), 
), 
Padding( 
padding: const EdgeInsets.all(20.0), 
child: Text( 
"Sorry ", 
style: TextStyle( 
fontSize: 20, 
), 
), 
), 
Text( 
" No music found!!", 
style: TextStyle( 
fontSize: 20, 
), 
), 
Padding( 
padding: const EdgeInsets.all(50.0), 
child: RaisedButton.icon( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(6.0), 
), 
color: Colors.deepOrange, 
icon: Icon(Icons.exit_to_app,color: Colors.white), 
onPressed: () { 
SystemNavigator.pop(); 
}, 
elevation: 10.0, 
label: Text("Exit",style: TextStyle(fontFamily: 'Bitter',color: 
Colors.white,fontSize: 18),), 
), 

], 
), 
), 
)), 
); 

 
Future<bool> _onWillPop() { 
return SystemNavigator.pop(); 


 
5)musichome.dart 
 
import 'dart:async'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:flutter/services.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/DataSearch.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/views/album.dart'; 
import 'package:music/views/artists.dart'; 
import 'package:music/views/home.dart'; 
import 'package:music/views/playlists.dart'; 
import 'package:music/views/songs.dart'; 
 
class MusicHome extends StatefulWidget { 
inal bottomItems = [ 
new BottomItem("Home", Icons.home), 
new BottomItem("Albums", Icons.album), 
new BottomItem("Songs", Icons.music_note), 
new BottomItem("Artists", Icons.person), 
new BottomItem("PlayList", Icons.playlist_add_check), 
]; 
@override 
State<StatefulWidget> createState() { 
return new _MusicState(); 


 
class _MusicState extends State<MusicHome> { 
int _selectedDrawerIndex = 0; 
List<Song> songs; 
String title = "Music player"; 
DatabaseClient db; 
bool isLoading = true; 
Song last; 
Color color = Colors.deepPurple; 
  
getDrawerItemWidget(int pos) { 
switch (pos) { 
case 0: 
return new Home(db); 
case 1: 
return new Album(db); 
case 2: 
return new Songs(db); 
case 3: 
return new Artists(db); 
case 4: 
return new PlayList(db,_selectedDrawerIndex); 
default: 
return new Text("Error"); 


 
_onSelectItem(int index) { 
setState(() => _selectedDrawerIndex = index); 
getDrawerItemWidget(_selectedDrawerIndex); 
title = widget.bottomItems[index].title; 

 
@override 
void initState() { 
super.initState(); 
getLast(); 

 
@override 
void dispose(){ 
super.dispose(); 

 
void getLast() async { 
db = new DatabaseClient(); 
await db.create(); 
last = await db.fetchLastSong(); 
songs = await db.fetchSongs(); 
setState(() { 
songs = songs; 
isLoading = false; 
}); 

 
GlobalKey<Sca oldState> sca oldState = new GlobalKey(); 
@override 
Widget build(BuildContext context) { 
var bottomOptions = <BottomNavigationBarItem>[]; 
for (var i = 0; i < widget.bottomItems.length; i++) { 
var d = widget.bottomItems[i]; 
bottomOptions.add( 
new BottomNavigationBarItem( 
icon: new Icon( 
d.icon, 
), 
label: d.title, 
backgroundColor: Theme.of(context).primaryColor, 
), 
); 

return new WillPopScope( 
child: new Sca old( 
key: sca oldState, 
appBar: _selectedDrawerIndex == 0 
? null 
: new AppBar( 
   
title: new Text(title), 
actions: <Widget>[ 
new IconButton( 
icon: Icon(Icons.search), 
onPressed: () { 
setState(() { 
showSearch( 
context: context, 
delegate: DataSearch(db, songs)); 
}); 
}), 
   
], 
), 
   
floatingActionButton: new FloatingActionButton( 
child: new Icon(Icons.play_circle_ illed), 
splashColor: Colors.white, 
tooltip: "Play", 
onPressed: () async{ 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
if (MyQueue.songs == null) { 
List<Song> list = new List(); 
list.add(last); 
MyQueue.songs = list; 
return new NowPlaying(db, list, 0,0); 
} else{ 
return new NowPlaying(db, MyQueue.songs, 
MyQueue.index,1); 
}})); 
}), 
   
body: isLoading 
? new Center( 
child: new CircularProgressIndicator(), 

: getDrawerItemWidget(_selectedDrawerIndex), 
bottomNavigationBar: new BottomNavigationBar( 
items: bottomOptions, 
selectedItemColor: Colors.white, 
unselectedItemColor: Color(0xFF333945), 
showSelectedLabels: true, 
showUnselectedLabels: false, 
type: BottomNavigationBarType.shifting, 
selectedIconTheme: IconThemeData(color: Colors.white), 
unselectedIconTheme: IconThemeData(color: 
Color(0xFF333945)), 
onTap: (index) => _onSelectItem(index), 
currentIndex: _selectedDrawerIndex, 
), 
), 
onWillPop: _onWillPop, 
); 

 
Future<bool> _onWillPop() { 
if (_selectedDrawerIndex != 0) { 
setState(() { 
_selectedDrawerIndex = 0; 
}); 

return showDialog( 
context: context, 
child: new AlertDialog( 
title: new Text('Are you sure?'), 
content: new Text('music player will be stopped..'), 
actions: <Widget>[ 
new FlatButton( 
onPressed: () => Navigator.of(context).pop(false), 
child: new Text( 
'No', 
), 
), 
new FlatButton( 
onPressed: () { 
MyQueue.player.stop(); 
SystemNavigator.pop(); 
}, 
child: new Text('Yes'), 
), 
], 
), 
) ?? 
false; 


class BottomItem { 
String title; 
IconData icon; 
BottomItem(this.title, this.icon);} 
 
6)home.dart 
 
import 'dart:math'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/AboutPage.dart'; 
import 'package:music/pages/DataSearch.dart'; 
import 'package:music/pages/card_detail.dart'; 
import 'package:music/pages/list_songs.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/pages/settings.dart'; 
import 'package:music/sc_model/model.dart'; 
import 'package:music/util/Music.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/util/utility.dart'; 
import 'package:scoped_model/scoped_model.dart'; 
 
class Home extends StatefulWidget { 
inal DatabaseClient db; 
Home(this.db); 
@override 
State<StatefulWidget> createState() { 
return new StateHome(); 


 
class StateHome extends State<Home> { 
List<Song> albums, recents, songs; 
int noOfFavorites; 
bool isLoading = true; 
Song last; 
Song top; 
Music selected = music[0]; 
 
void selectedMusic(Music music) { 
setState(() { 
selected = music; 
if (selected.title == 'Setting') { 
Navigator.push( 
context, MaterialPageRoute(builder: (context) => Settings())); 
} else { 
Navigator.push( 
context, MaterialPageRoute(builder: (context) => AboutPage())); 

}); 

 
@override 
void initState() { 
super.initState(); 
init(); 

 
void init() async { 
noOfFavorites = await widget.db.noOfFavorites(); 
albums = await widget.db.fetchRandomAlbum(); 
last = await widget.db.fetchLastSong(); 
songs = await widget.db.fetchSongs(); 
recents = await widget.db.fetchRecentSong(); 
recents.removeAt(0); 
top = await widget.db.fetchTopSong().then((item) => item[0]); 
 
ScopedModel.of<SongModel>(context, rebuildOnChange: 
true).init(widget.db); 
 
setState(() { 
isLoading = false; 
}); 

 
@override 
Widget build(BuildContext context) { 
return new CustomScrollView( 
slivers: <Widget>[ 
new SliverAppBar( 
expandedHeight: MediaQuery 
.of(context) 
.size 
.height / 2.4, 
floating: false, 
pinned: true, 
title: new Text("Music Player"), 
actions: <Widget>[ 
new IconButton( 
icon: Icon(Icons.search), 
onPressed: () { 
showSearch( 
context: context, delegate: DataSearch(widget.db, songs)); 
}), 
PopupMenuButton<Music>( 
onSelected: selectedMusic, 
elevation: 8, 
tooltip: 'Setting', 
itemBuilder: (context) { 
return music 
.map((Music m) => 
PopupMenuItem<Music>( 
value: m, 
child: ListTile( 
visualDensity: VisualDensity.standard, 
contentPadding: 
EdgeInsets.symmetric(horizontal: 30.0), 
leading: Text(m.title), 
), 
)) 
.toList(); 
}), 
], 
flexibleSpace: new FlexibleSpaceBar( 
// title:new Text("home"), 
background: new Stack( 
it: StackFit.expand, 
children: <Widget>[ 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return new Hero( 
tag: model.song == null ? "" : model.song.id, 
child: model.song == null 
? new Image.asset( 
"assets/back.jpg", 
it: BoxFit.cover, 

: getImage(model.song) != null 
? new Image. ile( 
getImage(model.song), 
it: BoxFit.cover, 

: new Image.asset( 
"assets/back.jpg", 
it: BoxFit.cover, 
), 
); 
}, 
), 
], 
), 
), 
), 
new SliverList( 
delegate: !isLoading 
? new SliverChildListDelegate(<Widget>[ 
new Padding( 
padding: 
const EdgeInsets.only(left: 8.0, top: 8.0, bottom: 8.0), 
child: new Text( 
"Quick actions", 
style: new TextStyle( 
fontWeight: FontWeight.bold, 
fontSize: 20.0, 
), 
), 
), 
new Row( 
mainAxisAlignment: MainAxisAlignment.spaceEvenly, 
children: <Widget>[ 
   
new Column( 
children: <Widget>[ 
new FloatingActionButton( 
heroTag: "Top", 
onPressed: () { 
Navigator.of(context).push( 
new MaterialPageRoute(builder: (context) { 
return new ListSongs(widget.db, 2); 
})); 
}, 
child: new Icon(Icons.show_chart), 
), 
new Padding( 
padding: 
const EdgeInsets.symmetric(vertical: 4.0)), 
new Text("Top songs"), 
], 
), 
new Column( 
mainAxisAlignment: MainAxisAlignment.spaceBetween, 
children: <Widget>[ 
new FloatingActionButton( 
heroTag: "favourites", 
onPressed: () { 
Navigator.of(context).push( 
new MaterialPageRoute(builder: (context) { 
return new ListSongs( 
widget.db, 3); 
})); 
}, 
child: new Icon(Icons.favorite_border), 
), 
new Padding( 
padding: 
const EdgeInsets.symmetric(vertical: 4.0)), 
new Text("Favourites"), 
], 
), 
new Column( 
children: <Widget>[ 
new FloatingActionButton( 
heroTag: "shu e", 
onPressed: () { 
MyQueue.songs = songs; 
Navigator.of(context).push( 
new MaterialPageRoute(builder: (context) { 
return new NowPlaying(widget.db, songs, 
new Random().nextInt(songs.length), 0); 
})); 
}, 
child: new Icon(Icons.shu e), 
), 
new Padding( 
padding: 
const EdgeInsets.symmetric(vertical: 4.0)), 
new Text("Random"), 
], 
), 
   
], 
), 
new Divider(), 
new Padding( 
padding: 
const EdgeInsets.only(left: 8.0, top: 8.0, bottom: 8.0), 
child: new Text( 
"Your recents!", 
style: new TextStyle( 
fontWeight: FontWeight.bold, 
fontSize: 20.0, 
), 
), 
), 
recentW(), 
new Divider(), 
new Padding( 
padding: 
const EdgeInsets.only(left: 8.0, top: 8.0, bottom: 8.0), 
child: new Text( 
"Albums you may like!", 
style: new TextStyle( 
fontWeight: FontWeight.bold, 
fontSize: 20.0, 
), 
), 
), 
new Container( 
//aspectRatio: 16/15, 
height: 160.0, 
child: new ListView.builder( 
itemCount: albums.length, 
scrollDirection: Axis.horizontal, 
itemBuilder: (context, i) => 
new InkResponse( 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.center, 
mainAxisAlignment: MainAxisAlignment.center, 
mainAxisSize: MainAxisSize.max, 
children: <Widget>[ 
Card( 
elevation: 12.0, 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(100) 
), 
child: new Hero( 
tag: albums[i].album, 
child: getImage(albums[i]) != null 
? CircleAvatar( 
radius: 50, 
backgroundImage: new FileImage( 
getImage(albums[i]), 
 
), 

: CircleAvatar( 
radius: 100, 
child: new Image.asset( 
"assets/back.jpg", 
 
it: BoxFit.cover, 
), 
), 
)), 
SizedBox( 
width: 200.0, 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Column( 
mainAxisAlignment: MainAxisAlignment.center, 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
Center( 
child: Text( 
albums[i].album, 
style: new TextStyle(fontSize: 18.0), 
maxLines: 1, 
textAlign: TextAlign.center, 
), 
), 
SizedBox(height: 8.0), 
Center( 
child: Text( 
albums[i].artist, 
maxLines: 1, 
textAlign: TextAlign.center, 
style: 
TextStyle(fontSize: 14.0, color: Colors.grey), 
), 

], 
), 
), 
), 
], 
), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new CardDetail(widget.db, albums[i], 0); 
})); 
}, 
), 
), 
), 
   
noOfFavorites != 0 ? favorites1() : Container(), 
new Divider(), 
new Padding( 
padding: 
const EdgeInsets.only( 
left: 20.0, top: 8.0, bottom: 8.0, right: 20), 
child: new Text( 
"Most played!", 
style: new TextStyle( 
fontWeight: FontWeight.bold, 
fontSize: 20.0, 
), 
), 
), 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return Padding( 
padding: const EdgeInsets.only(left:5.0,right:5.0,bottom: 10), 
child: new Card( 
elevation:12.0, 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(6.0), 
), 
child: new InkResponse( 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
SizedBox( 
child: new Hero( 
tag: _top(model).timestamp, 
child: getImage(_top(model)) != null 
? new Image. ile( 
getImage(_top(model)), 
height: 220.0, 
width: MediaQuery.of(context).size.width, 
it: BoxFit.cover, 

: new Image.asset( 
"assets/back.jpg", 
height: 220.0, 
width: MediaQuery.of(context).size.width, 
it: BoxFit.cover, 
), 
)), 
SizedBox( 
width: MediaQuery 
.of(context) 
.size 
.width, 
height: 70, 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: 
EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Column( 
crossAxisAlignment: CrossAxisAlignment 
.start, 
children: <Widget>[ 
Center( 
child: Text( 
_top(model).title, 
style: new TextStyle(fontSize: 18.0), 
maxLines: 1, 
), 
), 
SizedBox(height: 8.0), 
Center( 
child: Text( 
_top(model).artist, 
maxLines: 1, 
style: TextStyle( 
fontSize: 14.0, 
color: Colors.grey), 
), 

], 
), 
), 
), 
], 
), 
onTap: () { 
List<Song> list = new List(); 
list.add(_top(model)); 
MyQueue.songs = list; 
Navigator.of(context) 
.push( 
new MaterialPageRoute(builder: (context) { 
return new NowPlaying( 
widget.db, list, 0, 0); 
})); 
}, 
), 
), 
); 
}) 
]) 
: new SliverChildListDelegate(<Widget>[ 
new Center( 
child: new CircularProgressIndicator(), 

]), 
), 
], 
); 

 
Widget randomW() { 
return new Container( 
//aspectRatio: 16/15, 
height: 250.0, 
child: new ListView.builder( 
itemCount: albums.length, 
scrollDirection: Axis.horizontal, 
itemBuilder: (context, i) => 
new Card( 
child: new InkResponse( 
child: Column( 
mainAxisAlignment: MainAxisAlignment.center, 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
SizedBox( 
child: new Hero( 
tag: albums[i].album, 
child: getImage(albums[i]) != null 
? new Image. ile( 
getImage(albums[i]), 
height: 120.0, 
width: 200.0, 
it: BoxFit.cover, 

: new Image.asset( 
"assets/back.jpg", 
height: 120.0, 
width: 200.0, 
it: BoxFit.cover, 
), 
)), 
SizedBox( 
width: 200.0, 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Column( 
mainAxisAlignment: MainAxisAlignment.center, 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
Center( 
child: Text( 
albums[i].album, 
style: new TextStyle(fontSize: 18.0), 
maxLines: 1, 
), 
), 
SizedBox(height: 8.0), 
Center( 
child: Text( 
albums[i].artist, 
maxLines: 1, 
style: 
TextStyle(fontSize: 14.0, color: Colors.grey), 
), 

], 
), 
), 
), 
], 
), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new CardDetail(widget.db, albums[i], 0); 
})); 
}, 
), 
), 
), 
); 

 
Widget recentW() { 
return new Container( 
//aspectRatio: 16/15, 
height: 240.0, 
child: ScopedModelDescendant<SongModel>(builder: (context, 
child, model) { 
return new ListView.builder( 
itemCount: _recents(model).length, 
scrollDirection: Axis.horizontal, 
itemBuilder: (context, i) => 
new Card( 
child: new InkResponse( 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
SizedBox( 
child: new Hero( 
tag: _recents(model)[i], 
child: getImage(_recents(model)[i]) != null 
? new Image. ile( 
getImage(_recents(model)[i]), 
height: 160.0, 
width: 200.0, 
it: BoxFit.cover, 

: new Image.asset( 
"assets/back.jpg", 
height: 120.0, 
width: 200.0, 
it: BoxFit.cover, 
), 
), 
), 
SizedBox( 
width: 200.0, 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
Center( 
child: Text( 
_recents(model)[i].title, 
style: new TextStyle(fontSize: 18.0), 
maxLines: 1, 
), 
), 
SizedBox(height: 8.0), 
Center( 
child: Text( 
_recents(model)[i].artist, 
maxLines: 1, 
style: TextStyle( 
fontSize: 14.0, color: Colors.grey), 
), 

], 
), 
), 
), 
], 
), 
onTap: () { 
setState(() { 
MyQueue.songs = model.recents; 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new NowPlaying(widget.db, model.recents, i, 0); 
})); 
}); 
}, 
), 
)); 
}), 
); 

 
List<Song> _recents(SongModel model) { 
return model.recents == null ? recents : model.recents; 

 
Song _top(model) { 
return model.top == null ? top : model.top; 

 
 
Widget favorites1() { 
return Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
   
Divider(), 
new Padding( 
padding: const EdgeInsets.only(left: 15.0, top: 15.0, bottom: 10.0), 
child: new Text( 
"Favourites", 
style: new TextStyle( 
fontWeight: FontWeight.bold, 
fontSize: 15.0, 
letterSpacing: 2.0, 
color: Colors.black.withOpacity(0.75)), 
), 
), 
favoritesList(), 
], 
); 

 
// Done 
Widget favoritesList() { 
return new Container( 
//aspectRatio: 16/15, 
height: 240.0, 
child: FutureBuilder( 
future: widget.db.fetchFavSong(), 
builder: (context, AsyncSnapshot<List<Song>> snapshot) { 
switch (snapshot.connectionState) { 
case ConnectionState.none: 
break; 
case ConnectionState.waiting: 
return CircularProgressIndicator(); 
case ConnectionState.active: 
break; 
case ConnectionState.done: 
List<Song> favorites = snapshot.data; 
return ListView.builder( 
itemCount: favorites.length, 
scrollDirection: Axis.horizontal, 
itemBuilder: (context, i) => 
Padding( 
padding: const EdgeInsets.only(bottom: 15.0), 
child: new Card( 
elevation: 12.0, 
child: new InkResponse( 
child: ClipRRect( 
borderRadius: BorderRadius.circular(6.0), 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
SizedBox( 
child: getImage(favorites[i]) != null 
? new Image. ile( 
getImage(favorites[i]), 
height: 160.0, 
width: 200.0, 
it: BoxFit.cover, 

: new Image.asset( 
"images/back.jpg", 
height: 120.0, 
width: 180.0, 
it: BoxFit.cover, 
), 
), 
SizedBox( 
width: 200.0, 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: 
EdgeInsets.fromLTRB(10.0, 8.0, 0.0, 0.0), 
child: Column( 
crossAxisAlignment: CrossAxisAlignment 
.center, 
children: <Widget>[ 
Text( 
favorites[i].title, 
style: new TextStyle( 
fontSize: 18.0, 
fontWeight: FontWeight.w500, 
color: 
Colors.black.withOpacity(0.70)), 
maxLines: 1, 
), 
SizedBox(height: 5.0), 
Padding( 
padding: EdgeInsetsDirectional.only( 
bottom: 5.0), 
child: Text( 
favorites[i].artist, 
maxLines: 1, 
style: TextStyle( 
fontSize: 16.0, 
color: 
Colors.black.withOpacity(0.75)), 
), 

], 
), 
), 
), 
], 
), 
), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new NowPlaying(widget.db, favorites, i, 0); 
})); 
}, 
), 
), 
), 
); 

return Text('end'); 
}, 
), 
); 


 
 
7)Album.dart 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/card_detail.dart'; 
import 'package:music/util/utility.dart'; 
 
class Album extends StatefulWidget { 
inal DatabaseClient db; 
Album(this.db); 
@override 
State<StatefulWidget> createState() { 
return new _StateAlbum(); 


 
class _StateAlbum extends State<Album> { 
List<Song> songs; 
var f; 
bool isLoading = true; 
@override 
initState() { 
super.initState(); 
initAlbum(); 

 
void initAlbum() async { 
// songs=await widget.db.fetchSongs(); 
songs = await widget.db.fetchAlbum(); 
setState(() { 
isLoading = false; 
}); 

 
List<Card> _buildGridCards(BuildContext context) { 
return songs.map((song) { 
return Card( 
child: new InkResponse( 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
new Hero( 
tag: song.album, 
child: AspectRatio( 
aspectRatio: 18 / 16, 
child: getImage(song) != null 
? new Image. ile( 
getImage(song), 
height: 120.0, 
it: BoxFit.cover, 

: new Image.asset( 
"assets/back.jpg", 
height: 120.0, 
it: BoxFit.cover, 
), 
), 
), 
Expanded( 
child: Padding( 
// padding: EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), 
padding: EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
Flexible( 
child: Center( 
child: Text( 
song.album, 
style: new TextStyle(fontSize: 18.0), 
textAlign: TextAlign.center, 
maxLines: 2, 
), 
), 
), 
   
], 
), 
), 
), 
], 
), 
onTap: () { 
Navigator.push(context, new MaterialPageRoute(builder: 
(context) { 
return new CardDetail(widget.db, song, 0); 
})); 
}, 
), 
); 
}).toList(); 

 
@override 
Widget build(BuildContext context) { 
inal Orientation orientation = MediaQuery.of(context).orientation; 
return new Container( 
child: isLoading 
? new Center( 
child: new CircularProgressIndicator(), 

: new GridView.count( 
crossAxisCount: orientation == Orientation.portrait ? 2 : 4, 
children: _buildGridCards(context), 
padding: EdgeInsets.all(2.0), 
childAspectRatio: 8.0 / 10.0, 
)); 


 
8)songs.dart 
 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/util/utility.dart'; 
 
class Songs extends StatefulWidget { 
inal DatabaseClient db; 
Songs(this.db); 
@override 
State<StatefulWidget> createState() { 
return new _SongsState(); 


 
class _SongsState extends State<Songs> { 
List<Song> songs; 
bool isLoading = true; 
 
@override 
void initState() { 
super.initState(); 
initSongs(); 

 
void initSongs() async { 
songs = await widget.db.fetchSongs(); 
setState(() { 
isLoading = false; 
}); 

 
dynamic getImage(Song song) { 
return song.albumArt == null 
? null 
: new File.fromUri(Uri.parse(song.albumArt)); 

 
@override 
Widget build(BuildContext context) { 
return Container( 
child: isLoading 
? new Center( 
child: new CircularProgressIndicator(), 

: Column(children: <Widget>[ 
SizedBox( 
width: MediaQuery 
.of(context) 
.size 
.width - 20, 
child: OutlineButton( 
 
child: Text("Play All", style: TextStyle( 
fontSize: 20 
),), 
onPressed: () { 
MyQueue.songs = songs; 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new NowPlaying(widget.db, songs, 0,0); 
})); 
}, 
shape: new RoundedRectangleBorder( 
borderRadius: new BorderRadius.circular(30.0), 
)), 
), 
Expanded( 
child: new ListView.builder( 
itemCount: songs.length, 
itemBuilder: (context, i) => 
new Column( 
children: <Widget>[ 
new Divider( 
height: 8.0, 
), 
new ListTile( 
leading: new Hero( 
tag: songs[i].id, 
child: avatar(context, getImage(songs[i]), 
songs[i].title), 
), 
title: new Text(songs[i].title, 
maxLines: 1, 
style: new TextStyle(fontSize: 18.0)), 
subtitle: new Text( 
songs[i].artist, 
maxLines: 1, 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey), 
), 
trailing: new Text( 
new Duration(milliseconds: songs[i].duration) 
.toString() 
.split('.') 
. irst, 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey)), 
onTap: () { 
setState(() { 
MyQueue.songs = songs; 
Navigator.of(context).push( 
new MaterialPageRoute( 
builder: (context) => 
new NowPlaying( 
widget.db, MyQueue.songs, i,0))); 
}); 
}, 
onLongPress: () { 
setState(() { 
setFav(songs[i]); 
}); 
}, 
), 
], 
), 
), 

])); 

 
Future<void> setFav(song) { 
return showDialog( 
context: context, 
child: new AlertDialog( 
title: new Text('Add this song to favourites?'), 
content: new Text(song.title), 
actions: <Widget>[ 
new FlatButton( 
onPressed: () => Navigator.of(context).pop(false), 
child: new Text( 
'No', 
), 
), 
new FlatButton( 
onPressed: () async { 
await widget.db.favSong(song); 
 
Navigator.of(context).pop(); 
}, 
child: new Text('Yes'), 
), 
], 
), 
); 


 
9)NowPlaying.dart 
 
import 'dart:async'; 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:flutter/services.dart'; 
import 'package:media_noti ication/media_noti ication.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/sc_model/model.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/views/playlists.dart'; 
import 'package:scoped_model/scoped_model.dart'; 
import 'package:shared_preferences/shared_preferences.dart'; 
import 'package:volume/volume.dart'; 
import 'dart:math' as math; 
 
// ignore: must_be_immutable 
class NowPlaying extends StatefulWidget { 
inal List<Song> songs; 
int index; 
int mode; 
inal DatabaseClient db; 
NowPlaying(this.db, this.songs, this.index,this.mode); 
@override 
_NowPlayingState createState() => _NowPlayingState(); 

 
enum PlayerState { stopped, playing, paused } 
 
class _NowPlayingState extends State<NowPlaying> 
with TickerProviderStateMixin { 
AudioManager audioManager; 
 
bool loading; 
Song song; 
bool isPlayings = false; 
Animation animation; 
AnimationController animationController; 
Duration duration=Duration(); 
Duration position=Duration(); 
PlayerState playerState = PlayerState.stopped; 
bool isMuted; 
 
int maxVol, currentVol; 
List<Song> songs; 
inal saved = new Set<Song>(); 
 
List<BoxShadow> shadowList = [ 
BoxShadow( 
blurRadius: 3.0, 
color: Colors.grey[300], 
o set: O set(3, 3), 
), 
]; 
 
get isPlaying => playerState == PlayerState.playing; 
get isPaused => playerState == PlayerState.paused; 
IconData one; 
Color ones; 
double value = 0.0; 
int playerId; 
int quantity = 0; 
MusicFinder player; 
 
@override 
void initState() { 
super.initState(); 
isMuted = false; 
initAnim(); 
initPlayer(); 
initPlatformState(); 
MediaNoti ication.setListener('pause', () { 
setState((){ 
playpause(); 
}); 
}); 
 
MediaNoti ication.setListener('play', () { 
setState((){ 
playpause(); 
}); 
}); 
 
MediaNoti ication.setListener('next', () { 
setState((){ 
next(); 
}); 
}); 
 
MediaNoti ication.setListener('prev', () { 
setState((){ 
prev(); 
}); 
}); 
updatePage(widget.index); 
//widget.index++; 
animationController = AnimationController( 
vsync: this, 
animationBehavior: AnimationBehavior.preserve, 
duration: Duration(seconds: 10))..addListener(() { 
setState(() { 
   
}); 
}); 
animation = Tween<double>(begin: 0.0, end: 2 * math.pi).animate( 
CurvedAnimation(parent: animationController.view, curve: 
Curves.linear)); 
loading = false; 
animationController.repeat(); 
initPlatformState(); 

 
initAnim(){ 
_animationController = 
AnimationController(vsync: this, duration: Duration(milliseconds: 
500)) 
..addListener(() { 
setState(() { 
   
}); 
}); 
animateIcon = 
Tween<double>(begin: 0.0, end: 
1.0).animate(_animationController); 
animateColor = ColorTween( 
begin: Colors.deepOrange, 
end: Colors.deepOrangeAccent, 
).animate(CurvedAnimation( 
parent: _animationController.view, 
curve: Interval( 
0.00, 
1.00, 
curve: Curves.linear, 
), 
)); 

 
animateForward() { 
_animationController.forward(); 

 
animateReverse() { 
_animationController.reverse(); 

 
Future<void> hide() async { 
try { 
await MediaNoti ication.hide(); 
setState(() => status = 'hidden'); 
} on PlatformException {} 

 
Future<void> show(title, author) async { 
try { 
await MediaNoti ication.show(title: title, author: author,play: 
isPlayings); 
setState(() =>status = 'play'); 
} on PlatformException {} 

 
void onComplete() { 
setState(() { 
next(); 
}); 

 
void initPlayer() async { 
if (player == null) { 
player = MusicFinder(); 
MyQueue.player = player; 
var pref = await SharedPreferences.getInstance(); 
pref.setBool("played", true); 

setState(() { 
if (widget.mode == 0) { 
player.stop(); 

updatePage(widget.index); 
isPlayings = true; 
}); 
player.setDurationHandler((d) => setState(() { 
duration = d; 
})); 
player.setPositionHandler((p) => setState(() { 
position = p; 
})); 
player.setCompletionHandler(() { 
onComplete(); 
setState(() { 
position = duration; 
}); 
}); 
player.setErrorHandler((msg) { 
setState(() { 
playerState = PlayerState.stopped; 
player.stop(); 
duration = new Duration(seconds: 0); 
position = new Duration(seconds: 0); 
}); 
}); 
player.durationHandler.call(duration); 
player.positionHandler.call(position); 

 
void updatePage(int index) { 
MyQueue.index = index; 
song = widget.songs[index]; 
widget.index=index; 
song.timestamp = new DateTime.now().millisecondsSinceEpoch; 
if (song.count == null) { 
song.count = 0; 
} else { 
song.count++; 

if (widget.db != null && song.id != 9999) 
widget.db.updateSong(song); 
isFavourite = song.isFav; 
player.play(song.uri); 
animateReverse(); 
setState(() { 
isPlayings = true; 
isFavourite = song.isFav; 
status = 'play'; 
}); 
 
show(song.title, song.album); 
ScopedModel.of<SongModel>(context).updateUI(song, widget.db); 
 
animateReverse(); 

 
void playpause() { 
if (isPlayings) { 
player.pause(); 
animateForward(); 
animationController.reset(); 
setState(() { 
status = 'pause'; 
isPlayings = false; 
MediaNoti ication.show(title:song.title,author: song.album,play: 
isPlayings); 
//hide(); 
}); 
} else { 
   
player.play(song.uri); 
show(song.title, song.artist); 
animateReverse(); 
animationController.repeat(); 
setState(() { 
status = 'play'; 
isPlayings = true; 
MediaNoti ication.show(title:song.title,author:song.album,play: 
isPlayings); 
}); 

 

 
Future next() async { 
player.stop(); 
animationController.repeat(); 
setState(() { 
int i = ++widget.index; 
if (i >= widget.songs.length) { 
widget.index = 0; 
i = widget.index; 

updatePage(i); 
}); 

 
Future prev() async { 
player.stop(); 
animationController.repeat(); 
// int i=await widget.db.isfav(song); 
setState(() { 
int i = --widget.index; 
if (i < 0) { 
widget.index = 0; 
i = widget.index; 

 
updatePage(i); 
}); 

 
@override 
void dispose(){ 
animationController.stop(); 
_animationController.stop(); 
super.dispose();  

 
  
 
Future showBottomSheet() async { 
showModalBottomSheet( 
context: context, 
builder: (builder) { 
return Container( 
height: MediaQuery.of(context).size.height / 1.8, 
child: Column( 
children: <Widget>[ 
SizedBox(height: 4), 
Container( 
height: 60, 
child: Card( 
elevation: 10.0, 
child: Row( 
mainAxisAlignment: MainAxisAlignment.spaceBetween, 
children: <Widget>[ 
SizedBox(width: 10), 
Icon( 
Icons.list, 
size: 20, 
), 
Text( 
"Playing Queue", 
style: TextStyle( 
fontSize: 20, 
), 
textAlign: TextAlign.right, 
), 
Expanded( 
child: Text( 
"${widget.index + 1}/${widget.songs.length} song(s)\t\t", 
textAlign: TextAlign.right, 
)) 
], 
), 
), 
), 
Divider(), 
new Expanded( 
child: new ListView.builder( 
itemCount: widget.songs.length, 
itemBuilder: (context, i) => new Column( 
children: <Widget>[ 
new ListTile( 
leading: CircleAvatar( 
backgroundImage: FileImage(File.fromUri( 
Uri.parse(widget.songs[i].albumArt))), 
), 
title: new Text(widget.songs[i].title, 
maxLines: 1, style: new TextStyle(fontSize: 18.0)), 
subtitle: new Text( 
widget.songs[i].artist, 
maxLines: 1, 
style: 
new TextStyle(fontSize: 12.0, color: Colors.grey), 
), 
trailing: song.id == widget.songs[i].id 
? new Icon( 
Icons.play_circle_ illed, 
color: Colors.deepPurple, 

: new Text( 
(i + 1).toString(), 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey), 
), 
onTap: () { 
setState(() { 
player.stop(); 
updatePage(i); 
Navigator.pop(context); 
}); 
}, 
), 
new Divider( 
height: 8.0, 
), 
], 
), 
)), 
], 
), 
); 
}); 

 
Future<void> initPlatformState() async { 
await Volume.controlVolume(AudioManager.STREAM_MUSIC); 

 
adjustQuantity(press) { 
switch (press) { 
case 'MINUS': 
setState(() { 
setVol(quantity--); 
}); 
return; 
case 'PLUS': 
setState(() { 
setVol(quantity += 1); 
}); 
return; 


 
updateVolumes() async { 
maxVol = await Volume.getMaxVol; 
currentVol = await Volume.getVol; 

 
setVol(int i) async { 
await Volume.setVol(i, showVolumeUI: ShowVolumeUI.SHOW); 

 
Future mute(bool muted) async { 
inal result = await player.mute(muted); 
if (result == 1) 
setState(() { 
isMuted = muted; 
}); 

Future<void> setFav(song) async { 
var i = await widget.db.favSong(song); 
return i; 

int isFavourite; 
AnimationController _animationController; 
Animation<Color> animateColor; 
bool isOpened = true; 
String status = 'hidden'; 
Animation<double> animateIcon; 
GlobalKey<Sca oldState> sca oldKey = new 
GlobalKey<Sca oldState>(); 
 
 
@override 
Widget build(BuildContext context) { 
inal Orientation orientation = MediaQuery.of(context).orientation; 
 
return Sca old( 
key: sca oldKey, 
appBar: AppBar( 
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){ 
setState(() { 
player.stop(); 
MediaNoti ication.hide(); 
Navigator.pop(context); 
}); 
}), 
title: Text("Now Playing"), 
actions: [ 
IconButton(icon: Icon(Icons.playlist_add), onPressed: (){ 
setState(() { 
Navigator.of(context).push(MaterialPageRoute(builder: 
(context)=>new PlayList(widget.db,widget.index))); 
}); 
}), 
], 
), 
body: orientation==Orientation.portrait?portrait():landScape(), 
); 

Widget portrait(){ 
inal isFav = saved.contains(song); 
return ListView( 
physics: BouncingScrollPhysics(), 
scrollDirection: Axis.vertical, 
children: <Widget>[ 
SizedBox(height:30), 
Hero( 
tag: widget.index, 
child: Center( 
child: Stack( 
alignment: Alignment.bottomRight, 
children: <Widget>[ 
Container( 
width: 200, 
height: 200, 
decoration: BoxDecoration( 
color: Colors.white, 
boxShadow: shadowList, 
shape: BoxShape.circle, 
), 
child: Card( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(200), 
), 
child: Center( 
child: Transform.rotate( 
angle: animation.value, 
child:song==null?CircleAvatar( 
radius: 200, 
backgroundImage: 
AssetImage('assets/back.jpg')):CircleAvatar( 
radius: 200, 
backgroundImage: 
FileImage(File.fromUri(Uri.parse(song.albumArt))), 
), 
), 
), 
), 
), 
Padding( 
padding: const EdgeInsets.all(8.0), 
child: Container( 
width: 50, 
height: 50, 
decoration: BoxDecoration( 
boxShadow: shadowList, 
shape: BoxShape.circle, 
color: Colors.white, 
), 
child: Card( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(30)), 
child: IconButton( 
icon: Icon( 
isFav 
? Icons.favorite 
: Icons.favorite_border, 
color: 
isFav ? Colors.red : Colors.deepOrange), 
onPressed: () { 
setState(() { 
setFav(song); 
isFav ? saved.remove(song) : saved.add(song); 
inal SnackBar snackBar = SnackBar( 
content: Text( 
isFav 
? "${song.title} is unselected favourite song" 
: "${song.title} is selected favourite song", 
style: TextStyle(fontFamily: "Bitter"), 
)); 
sca oldKey.currentState.showSnackBar(snackBar); 
 
}); 
}), 
), 
), 
), 
], 
), 
), 
), 
SizedBox( 
height: 30, 
), 
Center( 
child: Column( 
mainAxisSize: MainAxisSize.max, 
mainAxisAlignment: MainAxisAlignment.center, 
children: <Widget>[ 
Text(song.title, 
textAlign: TextAlign.center, 
style: TextStyle(fontSize: 16)), 
SizedBox(height: 10), 
Text(song.artist, 
textAlign: TextAlign.center, 
style: TextStyle(fontSize: 16)), 
], 
), 
), 
SizedBox(height:20), 
Slider( 
value: position?.inSeconds?.toDouble(), 
min: 0.0, 
inactiveColor: Color(0xFF333945), 
max: duration?.inSeconds?.toDouble() ?? 0.0, 
activeColor: Colors.deepOrange, 
onChanged: (double value) { 
setState(() { 
player.seek(value.roundToDouble()); 
}); 
}), 
Row( 
mainAxisAlignment: MainAxisAlignment.spaceBetween, 
children: <Widget>[ 
Padding( 
padding: const EdgeInsets.all(16.0), 
child: Text( 
Duration(seconds: position?.inSeconds?.toInt() ?? 0) 
.toString() 
.split('.')[0], 
), 
), 
Padding( 
padding: const EdgeInsets.all(16.0), 
child: Text( 
Duration(seconds: duration?.inSeconds?.toInt() ?? 0) 
.toString() 
.split('.')[0]), 
), 
], 
), 
SizedBox(height: 20), 
Row( 
mainAxisAlignment: MainAxisAlignment.spaceEvenly, 
children: <Widget>[ 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: new IconButton( 
icon: new Icon(Icons.keyboard_arrow_left, 
color: Colors.deepOrange), 
onPressed: () { 
prev(); 
model.updateUI(song, widget.db); 
}), 
), 
); 
}, 
), 
//fab, 
Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: IconButton( 
icon: Icon(Icons.volume_o ), 
onPressed: () { 
setState(() { 
adjustQuantity('MINUS'); 
}); 
}, 
color: Colors.deepOrange), 
), 
), 
new FloatingActionButton( 
backgroundColor: animateColor.value, 
child: new AnimatedIcon( 
icon: AnimatedIcons.pause_play, progress: animateIcon), 
onPressed: (){ 
setState(() { 
playpause(); 
}); 
}, 
), 
Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: IconButton( 
icon: Icon(Icons.volume_up), 
onPressed: () { 
setState(() { 
adjustQuantity('PLUS'); 
}); 
}, 
color: Colors.deepOrange), 
), 
), 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: new IconButton( 
icon: new Icon(Icons.keyboard_arrow_right, 
color: Colors.deepOrange), 
onPressed: () { 
next(); 
model.updateUI(song, widget.db); 
}), 
), 
); 
}, 
), 
], 
), 
SizedBox( 
height:40, 
), 
SizedBox( 
child: GestureDetector( 
child: Center(child: Text('UP NEXT')), 
onTap: ()=>showBottomSheet(), 
), 
), 
SizedBox( 
height:20, 
), 
], 
); 

Widget landScape(){ 
inal isFav = saved.contains(song); 
return Row( 
mainAxisAlignment: MainAxisAlignment.spaceAround,  
crossAxisAlignment: CrossAxisAlignment.center, 
children: [ 
SizedBox(width:20), 
Column( 
mainAxisAlignment: MainAxisAlignment.center, 
children: [ 
Hero( 
tag: widget.index, 
child: Center( 
child: Stack( 
alignment: Alignment.bottomRight, 
children: <Widget>[ 
Container( 
width: 200, 
height: 200, 
decoration: BoxDecoration( 
color: Colors.white, 
boxShadow: shadowList, 
shape: BoxShape.circle, 
), 
child: Card( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(200), 
), 
child: Center( 
child: Transform.rotate( 
angle: animation.value, 
child:song==null?CircleAvatar( 
radius: 200, 
backgroundImage: 
AssetImage('assets/back.jpg')):CircleAvatar( 
radius: 200, 
backgroundImage: 
FileImage(File.fromUri(Uri.parse(song.albumArt))), 
), 
), 
), 
), 
), 
Padding( 
padding: const EdgeInsets.all(8.0), 
child: Container( 
width: 50, 
height: 50, 
decoration: BoxDecoration( 
boxShadow: shadowList, 
shape: BoxShape.circle, 
color: Colors.white, 
), 
child: Card( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(30)), 
child: IconButton( 
icon: Icon( 
isFav 
? Icons.favorite 
: Icons.favorite_border, 
color: 
isFav ? Colors.red : Colors.deepOrange), 
onPressed: () { 
setState(() { 
setFav(song); 
isFav ? saved.remove(song) : saved.add(song); 
inal SnackBar snackBar = SnackBar( 
content: Text( 
isFav 
? "${song.title} is unselected favourite song" 
: "${song.title} is selected favourite song", 
style: TextStyle(fontFamily: "Bitter"), 
)); 
sca oldKey.currentState.showSnackBar(snackBar); 
 
}); 
}), 
), 
), 
), 
], 
), 
), 
), 
 
], 
), 
Column( 
mainAxisAlignment: MainAxisAlignment.spaceBetween, 
children: [ 
SizedBox(height:20), 
Center( 
child: Column( 
mainAxisSize: MainAxisSize.max, 
mainAxisAlignment: MainAxisAlignment.center, 
children: <Widget>[ 
Text(song.title, 
textAlign: TextAlign.center, 
style: TextStyle(fontSize: 16)), 
SizedBox(height: 10), 
Text(song.artist, 
textAlign: TextAlign.center, 
style: TextStyle(fontSize: 16)), 
], 
), 
), 
SizedBox(height:10), 
Container( 
width: 300, 
child: Slider( 
value: position?.inSeconds?.toDouble(), 
min: 0.0, 
inactiveColor: Color(0xFF333945), 
max: duration?.inSeconds?.toDouble() ?? 0.0, 
activeColor: Colors.deepOrange, 
onChanged: (double value) { 
setState(() { 
player.seek(value.roundToDouble()); 
}); 
}), 
), 
Row( 
mainAxisAlignment: MainAxisAlignment.spaceBetween, 
crossAxisAlignment: CrossAxisAlignment.center, 
children: <Widget>[ 
Center( 
child: Text( 
Duration(seconds: position?.inSeconds?.toInt() ?? 0) 
.toString() 
.split('.')[0], 
), 
), 
SizedBox(width:200), 
Center( 
child: Text( 
Duration(seconds: duration?.inSeconds?.toInt() ?? 0) 
.toString() 
.split('.')[0]), 
), 
], 
), 
SizedBox(height: 10), 
Row( 
mainAxisAlignment: MainAxisAlignment.spaceEvenly, 
children: <Widget>[ 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: new IconButton( 
icon: new Icon(Icons.keyboard_arrow_left, 
color: Colors.deepOrange), 
onPressed: () { 
prev(); 
model.updateUI(song, widget.db); 
}), 
), 
); 
}, 
), 
//fab, 
Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: IconButton( 
icon: Icon(Icons.volume_o ), 
onPressed: () { 
setState(() { 
adjustQuantity('MINUS'); 
}); 
}, 
color: Colors.deepOrange), 
), 
), 
new FloatingActionButton( 
backgroundColor: animateColor.value, 
child: new AnimatedIcon( 
icon: AnimatedIcons.pause_play, progress: animateIcon), 
onPressed: (){ 
setState(() { 
playpause(); 
}); 
}, 
), 
Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: IconButton( 
icon: Icon(Icons.volume_up), 
onPressed: () { 
setState(() { 
adjustQuantity('PLUS'); 
}); 
}, 
color: Colors.deepOrange), 
), 
), 
ScopedModelDescendant<SongModel>( 
builder: (context, child, model) { 
return Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: Card( 
shape: RoundedRectangleBorder(borderRadius: 
BorderRadius.circular(40)), 
child: new IconButton( 
icon: new Icon(Icons.keyboard_arrow_right, 
color: Colors.deepOrange), 
onPressed: () { 
next(); 
model.updateUI(song, widget.db); 
}), 
), 
); 
}, 
), 
], 
), 
SizedBox( 
height:10, 
), 
SizedBox( 
child: GestureDetector( 
child: Center(child: Text('UP NEXT')), 
onTap: ()=>showBottomSheet(), 
), 
), 
SizedBox( 
height:10, 
), 
], 
), 
], 
); 


 
10)artists.dart 
 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/card_detail.dart'; 
 
class Artists extends StatefulWidget { 
inal DatabaseClient db; 
Artists(this.db); 
@override 
State<StatefulWidget> createState() { 
return new _StateArtist(); 


 
class _StateArtist extends State<Artists> { 
List<Song> songs; 
var f; 
bool isLoading = true; 
 
@override 
initState() { 
super.initState(); 
initArtists(); 

 
void initArtists() async { 
songs = await widget.db.fetchArtist(); 
setState(() { 
isLoading = false; 
}); 

 
List<Card> _buildGridCards(BuildContext context) { 
return songs.map((song) { 
return Card( 
child: new InkResponse( 
child: Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
children: <Widget>[ 
Hero( 
tag: song.artist, 
child: AspectRatio( 
aspectRatio: 18 / 16, 
child: new Image.asset( 
"assets/artist.png", 
height: 120.0, 
it: BoxFit.cover, 
), 
), 
), 
Expanded( 
child: Padding( 
padding: EdgeInsets.fromLTRB(4.0, 8.0, 0.0, 0.0), 
child: Center( 
child: Text( 
song.artist, 
textAlign: TextAlign.center, 
style: new TextStyle(fontSize: 18.0), 
maxLines: 1, 
), 
), 
), 
), 
], 
), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new CardDetail(widget.db, song, 1); 
})); 
}, 
), 
); 
}).toList(); 

 
@override 
Widget build(BuildContext context) { 
inal Orientation orientation = MediaQuery.of(context).orientation; 
return new Container( 
child: isLoading 
? new Center(child: new CircularProgressIndicator()) 
: new GridView.count( 
crossAxisCount: orientation == Orientation.portrait ? 2 : 4, 
children: _buildGridCards(context), 
padding: EdgeInsets.all(2.0), 
childAspectRatio: 8.0 / 10.0, 
)); 

  

 
11)CardDetail.dart 
 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/util/utility.dart'; 
 
class CardDetail extends StatefulWidget { 
  
inal Song song; 
inal int mode; 
inal DatabaseClient db; 
CardDetail(this.db, this.song, this.mode); 
@override 
State<StatefulWidget> createState() { 
return new StateCardDetail(); 


 
class StateCardDetail extends State<CardDetail> { 
List<Song> songs; 
bool isLoading = true; 
var image; 
@override 
void initState() { 
super.initState(); 
initAlbum(); 

 
void initAlbum() async { 
image = widget.song.albumArt == null 
? null 
: new File.fromUri(Uri.parse(widget.song.albumArt)); 
if (widget.mode == 0) 
songs = await 
widget.db.fetchSongsfromAlbum(widget.song.albumId); 
else 
songs = await widget.db.fetchSongsByArtist(widget.song.artist); 
setState(() { 
isLoading = false; 
}); 

 
@override 
Widget build(BuildContext context) { 
inal Orientation orientation = MediaQuery.of(context).orientation; 
return new Sca old( 
body: isLoading 
? new Center( 
child: new CircularProgressIndicator(), 

: new CustomScrollView( 
slivers: <Widget>[ 
new SliverAppBar( 
expandedHeight: 
orientation == Orientation.portrait ? 350.0 : 200.0, 
pinned: true, 
floating: true, 
title: Text(widget.song.album), 
flexibleSpace: new FlexibleSpaceBar( 
   
background: new Stack( 
it: StackFit.expand, 
children: <Widget>[ 
new Hero(  
tag: widget.mode == 0 
? widget.song.album 
: widget.song.artist, 
child: image != null 
? new Image. ile( 
image, 
it: BoxFit.cover, 

: Container(), 
), 
], 
), 
), 
), 
new SliverList( 
delegate: new SliverChildListDelegate(<Widget>[ 
new Padding( 
padding: const EdgeInsets.only(left: 8.0), 
child: new ListTile( 
title: Text(widget.mode == 0 
? widget.song.album 
: widget.song.artist, 
style: new TextStyle( 
fontSize: 20.0, fontWeight: FontWeight.bold), 
maxLines: 1,), 
subtitle: new Text( 
widget.mode == 0 ? widget.song.artist : "", 
style: new TextStyle(fontSize: 14.0), 
maxLines: 1, 
), 
trailing: new Text(songs.length.toString() + " songs"), 
), 
), 
   
   
new Padding( 
padding: const EdgeInsets.only(left: 8.0), 
child: new Text("Songs", 
style: new TextStyle( 
fontSize: 18.0, 
fontWeight: FontWeight.bold, 
))), 
]), 
), 
new SliverList( 
delegate: new SliverChildBuilderDelegate((builder, i) { 
return new ListTile( 
leading: new CircleAvatar( 
child: new Hero( 
tag: songs[i].id, 
child: avatar( 
context, getImage(songs[i]), songs[i].title), 
), 
), 
title: new Text(songs[i].title, 
maxLines: 1, style: new TextStyle(fontSize: 18.0)), 
subtitle: new Text( 
songs[i].artist, 
maxLines: 1, 
style: 
new TextStyle(fontSize: 12.0, color: Colors.grey), 
), 
trailing: new Text( 
new Duration(milliseconds: songs[i].duration) 
.toString() 
.split('.') 
. irst, 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey)), 
onTap: () { 
MyQueue.songs = songs; 
Navigator.of(context).push(new MaterialPageRoute( 
builder: (context) => 
new NowPlaying(widget.db, songs, i,0))); 
}, 
); 
}, childCount: songs.length), 
), 
], 
), 
floatingActionButton: new FloatingActionButton( 
onPressed: () { 
setState(() { 
MyQueue.songs = songs; 
Navigator.of(context).push(new MaterialPageRoute( 
builder: (context) => 
new NowPlaying(widget.db, MyQueue.songs, 0,0))); 
}); 
}, 
child: new Icon(Icons.shu e), 
), 
); 


 
12)playlist.dart 
 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/list_songs.dart'; 
 
 
class PlayList extends StatefulWidget { 
inal DatabaseClient db; 
inal int selectedDrawerIndex; 
/* inal List<Song> songs; */ 
PlayList(this.db,this.selectedDrawerIndex); 
 
@override 
State<StatefulWidget> createState() { 
return new _StatePlaylist(); 


 
class _StatePlaylist extends State<PlayList> { 
var mode; 
var selected; 
int selectedDrawerIndex; 
 
@override 
void initState() { 
mode = 1; 
selected = 1; 
selectedDrawerIndex=widget.selectedDrawerIndex; 
super.initState(); 

 
@override 
Widget build(BuildContext context) { 
return new Sca old( 
appBar: selectedDrawerIndex==4?null:AppBar( 
title:Text("PlayList"), 
actions: [ 
/* IconButton(icon: Icon(Icons.search), onPressed: (){ 
setState(() { 
showSearch(context: context, delegate: DataSearch(widget.db, 
widget.songs)); 
}); 
}), */ 
], 
), 
body: portrait(), 
); 

 
Widget portrait() { 
return new ListView( 
children: <Widget>[ 
new ListTile( 
leading: new Icon(Icons.call_received, 
color: Theme.of(context).accentColor), 
title: new Text("Recently played"), 
subtitle: new Text("songs"), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new ListSongs(widget.db, 1); 
})); 
}, 
), 
new Divider(), 
new ListTile( 
leading: 
new Icon(Icons.show_chart, color: 
Theme.of(context).accentColor), 
title: new Text("Top tracks"), 
subtitle: new Text("songs"), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new ListSongs(widget.db, 2); 
})); 
}, 
), 
new Divider(), 
new ListTile( 
leading: 
new Icon(Icons.favorite, color: Theme.of(context).accentColor), 
title: new Text("Favourites"), 
subtitle: new Text("Songs"), 
onTap: () { 
Navigator.of(context) 
.push(new MaterialPageRoute(builder: (context) { 
return new ListSongs(widget.db, 3); 
})); 
}, 
), 
new Divider(), 
], 
); 


 
13)ListSong.dart 
 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/util/lastplay.dart'; 
import 'package:music/util/utility.dart'; 
 
class ListSongs extends StatefulWidget { 
inal DatabaseClient db; 
inal int mode; 
ListSongs(this.db, this.mode); 
@override 
State<StatefulWidget> createState() { 
return new _ListSong(); 


 
class _ListSong extends State<ListSongs> { 
List<Song> songs; 
bool isLoading = true; 
 
@override 
void initState() { 
super.initState(); 
initSongs(); 

 
void initSongs() async { 
switch (widget.mode) { 
case 1: 
songs = await widget.db.fetchRecentSong(); 
break; 
case 2: 

songs = await widget.db.fetchTopSong(); 
break; 

case 3: 

songs = await widget.db.fetchFavSong(); 
break; 

default: 
break; 

 
setState(() { 
isLoading = false; 
}); 

 
Widget getTitle(int mode) { 
switch (mode) { 
case 1: 
return new Text("Recently played"); 
break; 
case 2: 
return new Text("Top tracks"); 
break; 
case 3: 
return new Text("Favourites"); 
break; 
default: 
return null; 


 
@override 
Widget build(BuildContext context) { 
return new Sca old( 
   
appBar: new AppBar( 
title: getTitle(widget.mode), 
), 
body: new Container( 
child: isLoading 
? new Center( 
child: new CircularProgressIndicator(), 

: new ListView.builder( 
itemCount: songs.length == null ? 0 : songs.length, 
itemBuilder: (context, i) => new Column( 
children: <Widget>[ 
   
new ListTile( 
leading: new Hero( 
tag: songs[i].id, 
child: avatar( 
context, getImage(songs[i]), songs[i].title), 
), 
title: new Text(songs[i].title, 
maxLines: 1, 
style: new TextStyle(fontSize: 18.0)), 
subtitle: new Text( 
songs[i].artist, 
maxLines: 1, 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey), 
), 
trailing: widget.mode == 2 
? new Text( 
(i + 1).toString(), 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey), 

: new Text( 
new Duration( 
milliseconds: songs[i].duration) 
.toString() 
.split('.') 
. irst, 
style: new TextStyle( 
fontSize: 12.0, color: Colors.grey)), 
onTap: () { 
MyQueue.songs = songs; 
Navigator.of(context).push(new MaterialPageRoute( 
builder: (context) => new NowPlaying( 
widget.db, MyQueue.songs, i,0))); 
}, 
onLongPress: () { 
if (widget.mode == 3) { 
showDialog( 
context: context, 
child: new AlertDialog( 
title: new Text( 
'Are you sure want to remove this song from 
favourites?'), 
content: new Text(songs[i].title), 
actions: <Widget>[ 
new FlatButton( 
onPressed: () => 
Navigator.of(context).pop(false), 
child: new Text( 
'No', 
), 
), 
new FlatButton( 
onPressed: () { 
widget.db.removeFavSong(songs[i]); 
 
setState(() { 
songs.removeAt(i); 
}); 
Navigator.of(context).pop(); 
}, 
child: new Text('Yes'), 
), 
], 
), 
); 

}, 
), 
], 
), 
), 
)); 


14)DataSearch.dart 
 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
import 'package:music/pages/NowPlaying.dart'; 
import 'package:music/util/lastplay.dart'; 
 
class DataSearch extends SearchDelegate{ 
inal DatabaseClient db; 
inal List<Song> songs; 
DataSearch(this.db,this.songs); 
 
@override 
String get searchFieldLabel =>'Search song,artist or album'; 
@override 
TextStyle get searchFieldStyle => TextStyle(fontSize: 16,fontFamily: 
"Bitter"); 
 
@override 
ThemeData appBarTheme(BuildContext context) { 
return ThemeData( 
primaryColor: Colors.white, 
cursorColor: Color(0xFF333945), 
); 

 
@override 
List<Widget> buildActions(BuildContext context) { 
return [ 
IconButton(icon: Icon(Icons.highlight_o ,color: 
Color(0xFF333945)), onPressed: (){ 
query=''; 
showSuggestions(context); 
}) 
]; 

  
@override 
Widget buildLeading(BuildContext context) { 
return IconButton(icon: AnimatedIcon( 
icon: AnimatedIcons.menu_arrow, 
progress: transitionAnimation),  
color: Color(0xFF333945), 
onPressed: (){ 
Navigator.pop(context); 
}); 

   
@override 
Widget buildResults(BuildContext context) { 
   
inal suggestionList=query.isEmpty?songs:songs 
.where((song) =>song.title.toLowerCase().startsWith(query) || 
song.artist.toLowerCase().startsWith(query) || 
song.album.toLowerCase().startsWith(query.toUpperCase())) 
.toList(); 
return suggestionList.isEmpty?Center(child: Text("No Music Found 
$query",style:TextStyle(fontSize: 20,fontFamily: 
"Bitter"))):ListView.builder( 
itemCount: suggestionList.length, 
itemBuilder: (context,index){ 
return ListTile( 
leading: new Hero( 
tag: suggestionList[index].id, 
child: 
CircleAvatar(backgroundImage:FileImage(File.fromUri(Uri.parse(sug
gestionList[index].albumArt)))), 
), 
title: new Text(suggestionList[index].title, 
maxLines: 1, style: new TextStyle(fontSize: 18.0)), 
subtitle: new Text( 
suggestionList[index].artist, 
maxLines: 1, 
style: new TextStyle(fontSize: 12.0), 
), 
trailing: new Text( 
new Duration(milliseconds: suggestionList[index].duration) 
.toString() 
.split('.') 
. irst, 
style: new TextStyle(fontSize: 12.0)), 
onTap: () { 
MyQueue.songs = suggestionList; 
Navigator.of(context).pop(); 
Navigator.of(context).push(new MaterialPageRoute( 
builder: (context) => 
new NowPlaying(db,suggestionList,index,0))); 
}, 
); 
}, 
); 

  
  
@override 
Widget buildSuggestions(BuildContext context) { 
   
inal suggestionList=query.isEmpty?songs:songs 
.where((song) =>song.title.toLowerCase().startsWith(query) || 
song.artist.toLowerCase().startsWith(query) || 
song.album.toLowerCase().startsWith(query)) 
.toList(); 
return ListView.builder( 
itemCount: suggestionList.length, 
itemBuilder: (context,index){ 
return ListTile( 
leading: new Hero( 
tag: suggestionList[index].id, 
child: 
CircleAvatar(backgroundImage:FileImage(File.fromUri(Uri.parse(sug
gestionList[index].albumArt)))), 
), 
title: new Text( 
suggestionList[index].title, 
   
style: new TextStyle(fontSize: 16.0, color: Colors.grey), 
), 
subtitle: new Text( 
suggestionList[index].artist, 
maxLines: 1, 
style: new TextStyle(fontSize: 12.0, color: Colors.grey), 
), 
trailing: new Text( 
new Duration(milliseconds: suggestionList[index].duration) 
.toString() 
.split('.') 
. irst, 
style: new TextStyle(fontSize: 12.0, color: Colors.grey)), 
onTap: () { 
showResults(context); 
MyQueue.songs = suggestionList; 
Navigator.of(context).pop(); 
Navigator.of(context).push(new MaterialPageRoute( 
builder: (context) => 
new NowPlaying(db,suggestionList,index,0))); 
}, 
); 
}, 
); 


 
15)setting.dart 
 
import 'package:dynamic_theme/dynamic_theme.dart'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
import 'package:music/database/database_client.dart'; 
 
class Settings extends StatefulWidget { 
@override 
State<StatefulWidget> createState() { 
return new _SettingState(); 


 
class _SettingState extends State<Settings> { 
var isLoading = false; 
var selected = 0; 
var db; 
 
@override 
void initState() { 
super.initState(); 
db = DatabaseClient(); 
db.create(); 

 
  
GlobalKey<Sca oldState> sca oldState = new GlobalKey(); 
 
Widget build(BuildContext context) { 
return new Sca old( 
key: sca oldState, 
appBar: new AppBar( 
title: new Text("Settings"), 
), 
body: new Container( 
child: Column( 
children: <Widget>[ 
new ListTile( 
leading: 
new Icon(Icons.style, color: Theme.of(context).accentColor), 
title: new Text(("Theme")), 
onTap: () { 
showDialog( 
context: context, 
builder: (context) { 
return new SimpleDialog( 
title: new Text("Select theme"), 
children: <Widget>[ 
new ListTile( 
title: Text("Light"), 
onTap: () { 
DynamicTheme.of(context).setBrightness( 
Brightness.light 
); 
   
Navigator.of(context).pop(); 
}, 
trailing: Theme 
.of(context) 
.brightness == 
Brightness.light 
? Icon(Icons.check) 
: null, 
), 
new ListTile( 
title: Text("Dark"), 
onTap: () { 
DynamicTheme.of(context).setBrightness( 
Brightness.dark); 
   
Navigator.of(context).pop(); 
}, 
trailing: Theme 
.of(context) 
.brightness == 
Brightness.dark 
? Icon(Icons.check) 
: null, 
), 
], 
); 
}); 
}), 
new Divider(), 
new ListTile( 
leading: new Icon( 
Icons.build, 
color: Theme.of(context).accentColor, 
), 
title: new Text("Re-scan/Reset Media"), 
onTap: () async { 
setState(() { 
isLoading = true; 
}); 
var db = new DatabaseClient(); 
await db.create(); 
var songs; 
try { 
songs = await MusicFinder.allSongs(); 
} catch (e) { 
print("failed to get songs"); 

List<Song> list = new List.from(songs); 
for (Song song in list)  
db.updateList(song); 
setState(() { 
isLoading = false; 
}); 
}, 
), 
new Divider(), 
 
 
new Container( 
child: isLoading 
? new Center( 
child: new Column( 
children: <Widget>[ 
new CircularProgressIndicator(), 
new Text("Loading Songs"), 
], 
), 

: new Container()), 
], 
), 
), 
); 


 
16)AboutPage.dart 
 
import 'package:flutter/material.dart'; 
 
class AboutPage extends StatelessWidget { 
@override 
Widget build(BuildContext context) { 
return Sca old( 
appBar: AppBar( 
title: Text('About'), 
), 
body: ListView( 
scrollDirection: Axis.vertical, 
children: <Widget>[ 
SizedBox(height: 40), 
Center( 
child: Container( 
width: 150, 
height: 150, 
child: Card( 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(100), 
), 
child: Card( 
elevation: 10.0, 
shape: RoundedRectangleBorder( 
borderRadius: BorderRadius.circular(100), 
), 
child: Hero( 
tag:'music', 
child: CircleAvatar( 
radius: 100, 
foregroundColor: Colors.white, 
backgroundColor: Colors.white, 
backgroundImage: AssetImage('assets/music 
player.png')), 
)), 
), 
), 
), 
SizedBox(height: 10), 
Center( 
child: Text("Music Player", 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600))), 
SizedBox(height: 10), 
Center( 
child: Text("Version:1.0.0", 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600))), 
SizedBox(height: 10), 
Divider(), 
Card( 
child: ExpansionTile( 
leading: Icon(Icons.featured_play_list), 
title: Text('Features', 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 
   
children: [ 
ListTile( 
title: 
Column( 
crossAxisAlignment: CrossAxisAlignment.start, 
mainAxisSize: MainAxisSize.max, children: <Widget>[ 
Text( 
"""Play local songs \n\n Beautiful Home screen \n\n Beautiful 
Now Playing \n\n Sqflite database support \n\n Search songs \n\n 
Songs suggestions \n\n Top tracks \n\n Recent songs \n\n Random 
song \n\n Album view \n\n Artist view \n\n Playlist \n\n Add to 
favourite \n\n Shu e \n\n Playing queue \n\n Play/pause \n\n 
Next/prev \n\n Theme(dark/light) \n\n Animations \n\n Play from SD 
card \n\n landscape mode supported \n\n""", 
textAlign: TextAlign.justify, 
style: TextStyle( 
fontSize: 16, 
   
fontFamily: "Bitter", 
fontWeight: FontWeight.w600),   
), 
]), 

], 
), 
), 
Card( 
child: ExpansionTile( 
leading: Icon(Icons.contact_mail), 
title: Text("Contact", 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 
children: [ 
ListTile( 
leading: Icon(Icons.email), 
title: Text("swarajya888@gmail.com",style:TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 
), 
ListTile( 
leading: Icon(Icons.location_on), 
title: Text("Pune",style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 
), 
ListTile( 
leading: Icon(Icons.phone), 
title: Text("+918668796251",style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 

], 
), 
), 
Card( 
child: ExpansionTile( 
leading: Icon(Icons.info), 
title: Text("About", 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600)), 
expandedAlignment: Alignment.centerLeft, 
expandedCrossAxisAlignment: CrossAxisAlignment.start, 
children: [ 
Center( 
child: Card( 
child: Padding( 
padding: const EdgeInsets.all(16.0), 
child: Text( 
"""Flutter is an open source framework to create high 
quality, high performance mobile applications across mobile 
operating systems - Android and iOS. It provides a simple, powerful, 
ef icient and easy to understand SDK to write mobile application in 
Google’s own language, Dart. This tutorial walks through the basics of 
Flutter framework, installation of Flutter SDK, setting up Android 
Studio to develop Flutter based application, architecture of Flutter 
framework and developing all type of mobile applications using 
Flutter framework.""", 
textAlign: TextAlign.justify, 
style: TextStyle( 
fontSize: 16, 
fontFamily: "Bitter", 
fontWeight: FontWeight.w600), 
), 
), 
), 
), 
], 
), 

], 
), 
); 


 
17)lastPlay.dart 
 
import 'package:flute_music_player/flute_music_player.dart'; 
 
class MyQueue { 
static List<Song> songs; // current playing queue 
static Song song; // current playing song 
static int index; // current playing song index 
static MusicFinder player = new MusicFinder(); 
static List<Song> allSongs; 

 
 
18)Music.dart 
 
class Music{ 
inal String title; 
const Music({this.title}); 

const List<Music> music=<Music>[ 
const Music(title: "Setting"), 
const Music(title:"About"), 
]; 
 
19)utility.dart 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:flutter/material.dart'; 
 
dynamic getImage(Song song) { 
return song.albumArt == null 
? null 
: new File.fromUri(Uri.parse(song.albumArt)); 

 
Widget avatar(context, File f, String title) { 
return new Material( 
borderRadius: new BorderRadius.circular(30.0), 
elevation: 2.0, 
child: f != null 
? new CircleAvatar( 
backgroundColor: Theme.of(context).accentColor, 
backgroundImage: new FileImage( 
f, 
), 

: new CircleAvatar( 
backgroundColor: Theme.of(context).accentColor, 
child: new Text(title[0].toUpperCase()), 
), 
); 

 
 
20)databaseClient.dart 
 
import 'dart:async'; 
import 'dart:io'; 
import 'package:flute_music_player/flute_music_player.dart'; 
import 'package:path/path.dart'; 
import 'package:path_provider/path_provider.dart'; 
import 'package:sqflite/sqflite.dart'; 
 
class DatabaseClient { 
Database _db; 
Song song; 
Future create() async { 
Directory directory = await getApplicationDocumentsDirectory(); 
String dbPath = join(directory.path, "database.db"); 
_db = await openDatabase(dbPath, version: 1, onCreate: this._create); 

 
Future _create(Database db, int version) async { 
await db.execute(""" 
CREATE TABLE songs(id NUMBER,title TEXT,duration 
NUMBER,albumArt TEXT,album TEXT,uri TEXT,artist TEXT,albumId 
NUMBER,isFav number NOT NULL default 0,timestamp 
number,count number not null default 0) 
"""); 
await db.execute(""" 
CREATE TABLE recents(id integer primary key autoincrement,title 
TEXT,duration NUMBER,albumArt TEXT,album TEXT,uri TEXT,artist 
TEXT,albumId NUMBER) 
"""); 

 
Future<int> updateInsertSongs(Song song) async { 
if (song.count == null) { 
song.count = 0; 

if (song.timestamp == null) { 
song.timestamp = 0; 

if (song.isFav == null) { 
song.isFav = 0; 

int id = 0; 
var count = Sqflite. irstIntValue(await _db 
.rawQuery("SELECT COUNT(*) FROM songs WHERE id = ?", 
[song.id])); 
if (count == 0) { 
id = await _db.insert("songs", song.toMap()); 
} else { 
await _db 
.update("songs", song.toMap(), where: "id= ?", whereArgs: 
[song.id]); 

return id; 

Future<int> updateList(Song song) async{ 
song.count=0; 
song.timestamp=new DateTime.now().millisecondsSinceEpoch; 
song.isFav=0; 
int id=0; 
var count=Sqflite. irstIntValue(await _db.rawQuery("SELECT 
COUNT(*) FROM songs WHERE title = ?", [song.title])); 
if(count==0){ 
id=await _db.insert("songs", song.toMap()); 

else { 
await _db 
.update("songs", song.toMap(), where: "title= ?", whereArgs: 
[song.title]); 

return id; 

Future<bool> alreadyLoaded() async { 
var count = 
Sqflite. irstIntValue(await _db.rawQuery("SELECT COUNT(*) FROM 
songs")); 
if (count > 0) { 
return true; 
} else { 
return false; 


 
Future<List<Song>> fetchSongs() async { 
List<Map> results = 
await _db.query("songs", columns: Song.Columns, orderBy: "title"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<List<Song>> fetchSongsfromAlbum(int id) async { 
List<Map> results = 
await _db.query("songs", columns: Song.Columns, where: 
"albumid=$id"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<List<Song>> fetchAlbum() async { 
// List<Map> results = await _db.query("songs", 
// distinct: true, 
//columns: Song.Columns ); 
List<Map> results = await _db.rawQuery( 
"select distinct albumid,album,artist ,albumArt from songs group 
by album order by album"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<List<Song>> fetchArtist() async { 
// List<Map> results = await _db.query("songs", 
// distinct: true, 
//columns: Song.Columns ); 
List<Map> results = await _db.rawQuery( 
"select distinct artist,album,albumArt from songs group by artist 
order by artist"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<List<Song>> fetchSongsByArtist(String artist) async { 
// List<Map> results = await _db.query("songs", 
// distinct: true, 
//columns: Song.Columns ); 
List<Map> results = await _db.query("songs", 
columns: Song.Columns, where: "artist='$artist'"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<List<Song>> fetchRandomAlbum() async { 
// List<Map> results = await _db.query("songs", 
// distinct: true, 
//columns: Song.Columns ); 
List<Map> results = await _db.rawQuery( 
"select distinct albumid,album,artist,albumArt from songs group 
by album order by RANDOM() limit 10"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
  
 
Future<List<Song>> fetchRecentSong() async { 
List<Map> results = 
await _db.rawQuery("select * from songs order by timestamp desc 
limit 25"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
 
 
Future<List<Song>> fetchTopSong() async { 
List<Map> results = 
await _db.rawQuery("select * from songs order by count desc limit 
25"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<int> updateSong(Song song) async { 
int id = 0; 
 
if (song.count == null) { 
song.count = 0; 

song.count += 1; 
await _db.update("songs", song.toMap(), 
where: "id= ?", whereArgs: [song.id]); 
 
return id; 

 
Future<int> isfav(Song song) async { 
var c = Sqflite. irstIntValue( 
await _db.rawQuery("select isFav from songs where 
is=${song.id}")); 
if (c == 0) { 
return 1; 
} else { 
return 0; 


 
Future<String> favSong(Song song) async { 
// var c = Sqflite. irstIntValue( 
// await _db.rawQuery("select isFav from songs where 
id=${song.id}")); 
// if (c == 0) { 
await _db.rawQuery("update songs set isFav =1 where 
id=${song.id}"); 
return "added"; 
// } else { 
// await _db.rawQuery("update songs set isFav =0 where 
id=${song.id}"); 
// return "removed"; 
// } 

 
Future<Song> fetchLastSong() async { 
List<Map> results = await _db 
.rawQuery("select * from songs order by timestamp desc limit 1"); 
Song song; 
results.forEach((s) { 
song = new Song.fromMap(s); 
}); 
return song; 

 
Future<List<Song>> fetchFavSong() async { 
List<Map> results = await _db.rawQuery("select * from songs where 
isFav=1"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 

 
Future<bool> removeFavSong(Song song) async { 
await _db.rawQuery("update songs set isFav= 0 where 
id=${song.id}"); 
 
return true; 

Future<List<Song>> searchSong(String q) async { 
 
List<Map> results = 
await _db.rawQuery("select * from songs where title like '%$q%'"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s);   
songs.add(song); 
}); 
return songs; 

Future<int> noOfFavorites() async { 
return Sqflite. irstIntValue( 
await _db.rawQuery("SELECT COUNT(*) FROM songs where isFav = 
1")); 

Future<List<Song>> fetchSongById(int id) async { 
List<Map> results = await _db.rawQuery("select * from songs where 
id=$id"); 
List<Song> songs = new List(); 
results.forEach((s) { 
Song song = new Song.fromMap(s); 
songs.add(song); 
}); 
return songs; 


 
 
 
 
 
 
 
 

You might also like