From 8cc82067f35d73a497175f70804f3e6674bb6cd5 Mon Sep 17 00:00:00 2001 From: kapiljhajhria Date: Sat, 15 Aug 2020 14:02:27 +0530 Subject: [PATCH 1/2] replaced search icon with search button --- lib/main.dart | 77 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 5d75cf3..71d31f4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -39,6 +39,7 @@ class AppName extends StatefulWidget { class AppState extends State { TextEditingController searchBar = new TextEditingController(); + bool fetchingSongs = false; void initState() { super.initState(); @@ -72,7 +73,11 @@ class AppState extends State { }); } - search(searchQuery) async { + search() async { + String searchQuery = searchBar.text; + if (searchQuery.isEmpty) return; +// fetchingSongs = true; + setState(() {}); await fetchSongsList(searchQuery); setState(() {}); } @@ -80,7 +85,8 @@ class AppState extends State { getSongDetails(String id, var context) async { await fetchSongDetails(id); checker = "Haa"; - Navigator.push(context, MaterialPageRoute(builder: (context) => AudioApp())); + Navigator.push( + context, MaterialPageRoute(builder: (context) => AudioApp())); } downloadSong(id) async { @@ -113,7 +119,8 @@ class AppState extends State { messageTextStyle: TextStyle(color: accent), progressWidget: Padding( padding: const EdgeInsets.all(20.0), - child: CircularProgressIndicator(valueColor: new AlwaysStoppedAnimation(accent)), + child: CircularProgressIndicator( + valueColor: new AlwaysStoppedAnimation(accent)), ), ); await pr.show(); @@ -121,19 +128,22 @@ class AppState extends State { final filename = title + ".m4a"; final artname = title + "_artwork.jpg"; - String dlPath = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_MUSIC); + String dlPath = await ExtStorage.getExternalStoragePublicDirectory( + ExtStorage.DIRECTORY_MUSIC); String filepath = dlPath + "/" + filename; String filepath2 = dlPath + "/" + artname; if (has_320 == "true") { kUrl = raw_kUrl.replaceAll("_96.mp4", "_320.mp4"); final client = http.Client(); - final request = new http.Request('HEAD', Uri.parse(kUrl))..followRedirects = false; + final request = new http.Request('HEAD', Uri.parse(kUrl)) + ..followRedirects = false; final response = await client.send(request); print(response.statusCode); kUrl = (response.headers['location']); print(raw_kUrl); print(kUrl); - final request2 = new http.Request('HEAD', Uri.parse(kUrl))..followRedirects = false; + final request2 = new http.Request('HEAD', Uri.parse(kUrl)) + ..followRedirects = false; final response2 = await client.send(request2); if (response2.statusCode != 200) { kUrl = kUrl.replaceAll(".mp4", ".mp3"); @@ -177,7 +187,13 @@ class AppState extends State { } print("Done"); Fluttertoast.showToast( - msg: "Download Complete!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.black, textColor: Color(0xff61e88a), fontSize: 14.0); + msg: "Download Complete!", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.black, + textColor: Color(0xff61e88a), + fontSize: 14.0); } else if (status.isDenied || status.isPermanentlyDenied) { Fluttertoast.showToast( msg: "Storage Permission Denied!\nCan't Download Songs", @@ -251,7 +267,8 @@ class AppState extends State { ), Text( " Now Playing", - style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600), + style: TextStyle( + fontSize: 15, fontWeight: FontWeight.w600), ) ], ), @@ -271,7 +288,11 @@ class AppState extends State { else Scaffold.of(contextt).showSnackBar(new SnackBar( content: new Text("Nothing is Playing."), - action: SnackBarAction(label: 'Okay', textColor: accent, onPressed: Scaffold.of(contextt).hideCurrentSnackBar), + action: SnackBarAction( + label: 'Okay', + textColor: accent, + onPressed: + Scaffold.of(contextt).hideCurrentSnackBar), backgroundColor: Colors.black38, duration: Duration(seconds: 2), )) @@ -315,7 +336,10 @@ class AppState extends State { icon: Icon(MdiIcons.dotsVertical), color: accent, onPressed: () => { - Navigator.push(context, MaterialPageRoute(builder: (context) => AboutPage())), + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => AboutPage())), }), ) ]), @@ -323,7 +347,7 @@ class AppState extends State { new Padding(padding: EdgeInsets.only(top: 20)), new TextField( onSubmitted: (String value) { - search(value); + search(); }, controller: searchBar, style: TextStyle( @@ -344,9 +368,15 @@ class AppState extends State { borderRadius: BorderRadius.all(Radius.circular(100)), borderSide: BorderSide(color: accent), ), - suffixIcon: Icon( - Icons.search, + suffixIcon: IconButton( + icon: Icon( + Icons.search, + color: accent, + ), color: accent, + onPressed: () { + search(); + }, ), border: InputBorder.none, hintText: "Search...", @@ -370,12 +400,14 @@ class AppState extends State { padding: const EdgeInsets.only(top: 5, bottom: 5), child: Card( color: Colors.black12, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0)), elevation: 0, child: InkWell( borderRadius: BorderRadius.circular(10.0), onTap: () { - getSongDetails(searchedList[index]["id"], context); + getSongDetails( + searchedList[index]["id"], context); }, splashColor: accent, hoverColor: accent, @@ -393,14 +425,23 @@ class AppState extends State { ), ), title: Text( - (searchedList[index]['title']).toString().split("(")[0].replaceAll(""", "\"").replaceAll("&", "&"), + (searchedList[index]['title']) + .toString() + .split("(")[0] + .replaceAll(""", "\"") + .replaceAll("&", "&"), style: TextStyle(color: Colors.white), ), subtitle: Text( - searchedList[index]['more_info']["singers"], + searchedList[index]['more_info'] + ["singers"], style: TextStyle(color: Colors.white), ), - trailing: IconButton(color: accent, icon: Icon(MdiIcons.downloadOutline), onPressed: () => downloadSong(searchedList[index]["id"])), + trailing: IconButton( + color: accent, + icon: Icon(MdiIcons.downloadOutline), + onPressed: () => downloadSong( + searchedList[index]["id"])), ), ], ), From 04f9328886c5d0bca5406e964a3d6fa6449bd363 Mon Sep 17 00:00:00 2001 From: kapiljhajhria Date: Sat, 15 Aug 2020 14:20:44 +0530 Subject: [PATCH 2/2] replaced search icon with icon button. and also added circular progress indicator for user feedback --- lib/main.dart | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 71d31f4..f1df959 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -76,9 +76,10 @@ class AppState extends State { search() async { String searchQuery = searchBar.text; if (searchQuery.isEmpty) return; -// fetchingSongs = true; + fetchingSongs = true; setState(() {}); await fetchSongsList(searchQuery); + fetchingSongs = false; setState(() {}); } @@ -369,10 +370,21 @@ class AppState extends State { borderSide: BorderSide(color: accent), ), suffixIcon: IconButton( - icon: Icon( - Icons.search, - color: accent, - ), + icon: fetchingSongs + ? SizedBox( + height: 18, + width: 18, + child: Center( + child: CircularProgressIndicator( + valueColor: + new AlwaysStoppedAnimation( + accent)), + ), + ) + : Icon( + Icons.search, + color: accent, + ), color: accent, onPressed: () { search();