From aa3bf2b39da9c13fc18d58bd5cce86de79e36e06 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Thu, 23 Apr 2020 12:59:46 +0530 Subject: [PATCH 1/8] Routing Maps and widget lifecycle in flutter --- .gitignore | 2 +- lib/main.dart | 49 +++++++--------------------------- lib/pages/choose_location.dart | 31 +++++++++++++++++++++ lib/pages/home.dart | 34 +++++++++++++++++++++++ lib/pages/loading.dart | 19 +++++++++++++ 5 files changed, 94 insertions(+), 41 deletions(-) create mode 100644 lib/pages/choose_location.dart create mode 100644 lib/pages/home.dart create mode 100644 lib/pages/loading.dart diff --git a/.gitignore b/.gitignore index ae1f183..b4a256a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ # The .vscode folder contains launch configuration and tasks you configure in # VS Code which you may wish to be included in version control, so this line # is commented out by default. -#.vscode/ +.vscode/ # Flutter/Dart/Pub related **/doc/api/ diff --git a/lib/main.dart b/lib/main.dart index 746e932..4b761f0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,45 +1,14 @@ import 'package:flutter/material.dart'; +import 'package:my_new_app/pages/choose_location.dart'; +import 'package:my_new_app/pages/home.dart'; +import 'package:my_new_app/pages/loading.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, - home: CardId(), + initialRoute: '/home', + routes: { + '/': (context) => Loading(), + '/locate': (context) => LocationChooser(), + '/home': (context) => Home(), + }, )); - - - -class CardId extends StatelessWidget { - @override - Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.white, - appBar: AppBar( - elevation: 0.0, - backgroundColor: Colors.grey[50], - title: Text( - 'My Profile', - style: TextStyle( - fontFamily: 'Ubuntu', - fontWeight: FontWeight.bold, - letterSpacing: 2.0, - color: Colors.amber[800]), - ), - centerTitle: true, - ), - body: Padding( - padding: EdgeInsets.all(20.0), - child: Text('main'), - ), - floatingActionButton: FloatingActionButton( - onPressed: (){}, - elevation: 10.30, - backgroundColor:Colors.yellow[50], - child: Icon( - Icons.add, - color:Colors.yellow[900], - ), - ), - ); - } -} - - diff --git a/lib/pages/choose_location.dart b/lib/pages/choose_location.dart new file mode 100644 index 0000000..47f9c8e --- /dev/null +++ b/lib/pages/choose_location.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; + +class LocationChooser extends StatefulWidget { + @override + _LocationChooserState createState() => _LocationChooserState(); +} + +class _LocationChooserState extends State { + @override + void initState() { + super.initState(); + print('Hwllo from initstate'); + } + + int counter = 0; + @override + Widget build(BuildContext context) { + print('hello from build'); //when the object rebuild this will add value to the console + return Scaffold( + appBar: AppBar( + title: Text('Choose location'), + ), + body: RaisedButton( + onPressed: () { + setState(() { + counter +=1; + }); + }, + child: Text('count $counter'))); + } +} diff --git a/lib/pages/home.dart b/lib/pages/home.dart new file mode 100644 index 0000000..89bb936 --- /dev/null +++ b/lib/pages/home.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; + +class Home extends StatefulWidget { + @override + _HomeState createState() => _HomeState(); +} + +class _HomeState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Home')), + body: SafeArea( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Center( + child: Text( + 'main screen', + style: TextStyle(fontSize: 20.5, color: Colors.red), + ), + ), + FlatButton.icon( + onPressed: () { + Navigator.pushNamed(context, '/locate'); + }, + icon: Icon(Icons.edit_location), + label: Text('choose your current location'), + ) + ], + ), + )); + } +} diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart new file mode 100644 index 0000000..9897df0 --- /dev/null +++ b/lib/pages/loading.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; + +class Loading extends StatefulWidget { + @override + _LoadingState createState() => _LoadingState(); +} + +class _LoadingState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text('Loading')), + body: SafeArea( + child: Center( + child: Text('Loading Screen'), + ), + )); + } +} From 470037c77e5a122447dce2ca64b80c5d9b4b41a7 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Thu, 23 Apr 2020 13:54:21 +0530 Subject: [PATCH 2/8] async await in Flutter --- lib/pages/choose_location.dart | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/pages/choose_location.dart b/lib/pages/choose_location.dart index 47f9c8e..fafc163 100644 --- a/lib/pages/choose_location.dart +++ b/lib/pages/choose_location.dart @@ -6,26 +6,46 @@ class LocationChooser extends StatefulWidget { } class _LocationChooserState extends State { + + void getdata() async { + //TODO: this approach will fail if the data dependent on each other. + + // //api simulated + // var k = Future.delayed(Duration(seconds: 3),()=>print('Return Hello from simulated api')); + // var g = Future.delayed(Duration(seconds: 2),()=>print('Return data from simulated 2nd api')); + // print('$g,$k'); + +//TODO: async await approach if the data dependent each other on to then + + //api simulated + String data1 = await Future.delayed(Duration(seconds: 3),()=>'Return Hello from simulated api'); + String data2 = await Future.delayed(Duration(seconds: 2),()=>'Return data from simulated 2nd api'); + print("data1=$data1 data2 = $data2"); //will be execute together + + } + @override void initState() { super.initState(); - print('Hwllo from initstate'); + getdata(); + print('Hwllo from initstate'); //this will be not get blocked because of async approach. } int counter = 0; @override Widget build(BuildContext context) { - print('hello from build'); //when the object rebuild this will add value to the console + print( + 'hello from build'); //when the object rebuild this will add value to the console return Scaffold( appBar: AppBar( title: Text('Choose location'), ), body: RaisedButton( - onPressed: () { - setState(() { - counter +=1; - }); - }, - child: Text('count $counter'))); + onPressed: () { + setState(() { + counter += 1; + }); + }, + child: Text('count $counter'))); } } From 0f8b0bbeb08cb73746a73b8d7dc858fefed7f2d4 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:03:19 +0530 Subject: [PATCH 3/8] Http request to get data in flutter --- lib/main.dart | 5 ++--- lib/pages/choose_location.dart | 27 --------------------------- lib/pages/home.dart | 11 ++++++++++- lib/pages/loading.dart | 16 +++++++++++++++- pubspec.lock | 14 ++++++++++++++ pubspec.yaml | 1 + 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 4b761f0..1e09176 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,10 +5,9 @@ import 'package:my_new_app/pages/loading.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, - initialRoute: '/home', routes: { - '/': (context) => Loading(), + '/': (context) =>Home(), '/locate': (context) => LocationChooser(), - '/home': (context) => Home(), + '/load': (context) =>Loading(), }, )); diff --git a/lib/pages/choose_location.dart b/lib/pages/choose_location.dart index fafc163..9b50ebb 100644 --- a/lib/pages/choose_location.dart +++ b/lib/pages/choose_location.dart @@ -6,36 +6,9 @@ class LocationChooser extends StatefulWidget { } class _LocationChooserState extends State { - - void getdata() async { - //TODO: this approach will fail if the data dependent on each other. - - // //api simulated - // var k = Future.delayed(Duration(seconds: 3),()=>print('Return Hello from simulated api')); - // var g = Future.delayed(Duration(seconds: 2),()=>print('Return data from simulated 2nd api')); - // print('$g,$k'); - -//TODO: async await approach if the data dependent each other on to then - - //api simulated - String data1 = await Future.delayed(Duration(seconds: 3),()=>'Return Hello from simulated api'); - String data2 = await Future.delayed(Duration(seconds: 2),()=>'Return data from simulated 2nd api'); - print("data1=$data1 data2 = $data2"); //will be execute together - - } - - @override - void initState() { - super.initState(); - getdata(); - print('Hwllo from initstate'); //this will be not get blocked because of async approach. - } - int counter = 0; @override Widget build(BuildContext context) { - print( - 'hello from build'); //when the object rebuild this will add value to the console return Scaffold( appBar: AppBar( title: Text('Choose location'), diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 89bb936..6f2104a 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -26,7 +26,16 @@ class _HomeState extends State { }, icon: Icon(Icons.edit_location), label: Text('choose your current location'), - ) + ), + FlatButton( + onPressed: () { + Navigator.pushNamed(context, '/load'); + }, + child: Icon( + Icons.get_app, + color: Colors.red, + semanticLabel: 'Get DAta', + )) ], ), )); diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index 9897df0..32a1a70 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -1,11 +1,25 @@ import 'package:flutter/material.dart'; - +import 'package:http/http.dart'; +import 'dart:convert'; class Loading extends StatefulWidget { @override _LoadingState createState() => _LoadingState(); } class _LoadingState extends State { + + void getdata() async { + Response response = await get('https://jsonplaceholder.typicode.com/todos/2');// create request and get the data + Map data = jsonDecode(response.body); //decode the json + print(data); + } + + @override + void initState() { + super.initState(); + getdata(); + } + @override Widget build(BuildContext context) { return Scaffold( diff --git a/pubspec.lock b/pubspec.lock index fcf6763..2b8842a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -74,6 +74,20 @@ packages: description: flutter source: sdk version: "0.0.0" + http: + dependency: "direct dev" + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.0+4" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.4" image: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7772676..e6b16e8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + http: ^0.12.0+4 # For information on the generic Dart part of this file, see the From 3cde87e5a42a47df233a454ec1969a872e2cf9ae Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:28:02 +0530 Subject: [PATCH 4/8] Working with Api and manipulating data --- lib/main.dart | 1 + lib/pages/loading.dart | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1e09176..f9e60e2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:my_new_app/pages/loading.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, + initialRoute: '/load', routes: { '/': (context) =>Home(), '/locate': (context) => LocationChooser(), diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index 32a1a70..b9893fc 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -1,32 +1,58 @@ import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'dart:convert'; + class Loading extends StatefulWidget { @override _LoadingState createState() => _LoadingState(); } class _LoadingState extends State { - - void getdata() async { - Response response = await get('https://jsonplaceholder.typicode.com/todos/2');// create request and get the data - Map data = jsonDecode(response.body); //decode the json - print(data); + + void getTimeData() async { + /*requesting the data*/ + + //make the request to the server end Point + Response response = await get('http://worldtimeapi.org/api/timezone/Asia/Kolkata'); + + /* Storing and parsing data */ + + // Parse the data + Map getdata = jsonDecode(response.body); + //storing the needed data in separate varriable + String datetime = getdata['datetime']; + //add substring to cut the '+0' + String offset = getdata['utc_offset'].substring(2, 6); + + /* manipulating data*/ + +//add substring to cut the all except 5 convert into a integer + int offsetHours = int.parse(offset.substring(0, 1)); +//add substring to cut the all except 30 and convert into a integer + int offsetMinute = int.parse(offset.substring(2,4)); + + //creating datetime object from the string parsing + DateTime now = DateTime.parse(datetime); + + //adding offset hours and minutes to the datetime + + now = now.add(Duration(hours: offsetHours, minutes: offsetMinute)); + } @override void initState() { super.initState(); - getdata(); + getTimeData(); } - + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Loading')), body: SafeArea( child: Center( - child: Text('Loading Screen'), + child: Text('Loading..'), ), )); } From 34f6567bff758f0e91863f375e450183dca68111 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Fri, 24 Apr 2020 15:14:30 +0530 Subject: [PATCH 5/8] Custom and reusable widget of Worldtime --- lib/pages/loading.dart | 46 ++++++++++------------------------ lib/services/worldTime.dart | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 lib/services/worldTime.dart diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index b9893fc..5018aee 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:http/http.dart'; -import 'dart:convert'; +import 'package:my_new_app/services/worldTime.dart'; class Loading extends StatefulWidget { @override @@ -8,43 +7,24 @@ class Loading extends StatefulWidget { } class _LoadingState extends State { + + String nowTime = 'Loading....☁☁'; //add as a placeholder - void getTimeData() async { - /*requesting the data*/ - - //make the request to the server end Point - Response response = await get('http://worldtimeapi.org/api/timezone/Asia/Kolkata'); - - /* Storing and parsing data */ - - // Parse the data - Map getdata = jsonDecode(response.body); - //storing the needed data in separate varriable - String datetime = getdata['datetime']; - //add substring to cut the '+0' - String offset = getdata['utc_offset'].substring(2, 6); - - /* manipulating data*/ - -//add substring to cut the all except 5 convert into a integer - int offsetHours = int.parse(offset.substring(0, 1)); -//add substring to cut the all except 30 and convert into a integer - int offsetMinute = int.parse(offset.substring(2,4)); - - //creating datetime object from the string parsing - DateTime now = DateTime.parse(datetime); - - //adding offset hours and minutes to the datetime - - now = now.add(Duration(hours: offsetHours, minutes: offsetMinute)); + void setTime() async { + WorldTime currentTime = WorldTime(location:'kolkata', url:'Asia/Kolkata',flag: 'get.png'); + await currentTime.getTime(); + print(currentTime.time); + setState(() { + nowTime =currentTime.time; //setting the real value + }); } @override void initState() { super.initState(); - getTimeData(); - } + setTime(); + } @override Widget build(BuildContext context) { @@ -52,7 +32,7 @@ class _LoadingState extends State { appBar: AppBar(title: Text('Loading')), body: SafeArea( child: Center( - child: Text('Loading..'), + child: Text('$nowTime'), ), )); } diff --git a/lib/services/worldTime.dart b/lib/services/worldTime.dart new file mode 100644 index 0000000..8dd6361 --- /dev/null +++ b/lib/services/worldTime.dart @@ -0,0 +1,50 @@ +import 'package:http/http.dart'; +import 'dart:convert'; + +class WorldTime { + String location; //ui friendly location + String flag; //custom image + String time; //readable time + String url; //url to go the the timezone + + WorldTime({this.location, this.flag, this.url}); + + Future getTime() async { + try { + /*requesting the data*/ + + //make the request to the server end Point + Response response = + await get('http://worldtimeapi.org/api/timezone/$url'); + + /* Storing and parsing data */ + + // Parse the data + Map getdata = jsonDecode(response.body); + //storing the needed data in separate varriable + String datetime = getdata['datetime']; + //add substring to cut the '+0' + String offset = getdata['utc_offset'].substring(2, 6); + + /* manipulating data*/ + +//add substring to cut the all except 5 convert into a integer + int offsetHours = int.parse(offset.substring(0, 1)); +//add substring to cut the all except 30 and convert into a integer + int offsetMinute = int.parse(offset.substring(2, 4)); + + //creating datetime object from the string parsing + DateTime now = DateTime.parse(datetime); + + //adding offset hours and minutes to the datetime + + now = now.add(Duration(hours: offsetHours, minutes: offsetMinute)); + + time = '${now.toString()} 🧭'; //adding actual time to the time varriable + + } catch (e) { + print('this is a error $e'); + time = 'Could not get the Data..😢'; + } + } +} From f52e0e0a7f771b557fb693f30167aa176d29b8ed Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Sat, 25 Apr 2020 21:57:47 +0530 Subject: [PATCH 6/8] Passing data to different route --- lib/main.dart | 5 ++--- lib/pages/home.dart | 9 ++++++++- lib/pages/loading.dart | 14 +++++++------- lib/services/worldTime.dart | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f9e60e2..e68aece 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,10 +5,9 @@ import 'package:my_new_app/pages/loading.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, - initialRoute: '/load', routes: { - '/': (context) =>Home(), + '/home': (context) =>Home(), '/locate': (context) => LocationChooser(), - '/load': (context) =>Loading(), + '/': (context) =>Loading(), }, )); diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 6f2104a..cc52450 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -6,8 +6,15 @@ class Home extends StatefulWidget { } class _HomeState extends State { + + Map data = {}; + @override Widget build(BuildContext context) { + + data = ModalRoute.of(context).settings.arguments; //receiving the data from different route. + print(data); + return Scaffold( appBar: AppBar(title: Text('Home')), body: SafeArea( @@ -16,7 +23,7 @@ class _HomeState extends State { children: [ Center( child: Text( - 'main screen', + '${data['time']}', style: TextStyle(fontSize: 20.5, color: Colors.red), ), ), diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index 5018aee..5127999 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -8,16 +8,16 @@ class Loading extends StatefulWidget { class _LoadingState extends State { - String nowTime = 'Loading....☁☁'; //add as a placeholder + void setTime() async { WorldTime currentTime = WorldTime(location:'kolkata', url:'Asia/Kolkata',flag: 'get.png'); await currentTime.getTime(); - print(currentTime.time); - - setState(() { - nowTime =currentTime.time; //setting the real value - }); + Navigator.pushReplacementNamed(context, '/home',arguments: { + 'location':currentTime.location, + 'flag':currentTime.flag, + 'time':currentTime.time + }); //sending data to different route using arguments. } @override @@ -32,7 +32,7 @@ class _LoadingState extends State { appBar: AppBar(title: Text('Loading')), body: SafeArea( child: Center( - child: Text('$nowTime'), + child: Text('loading...'), ), )); } diff --git a/lib/services/worldTime.dart b/lib/services/worldTime.dart index 8dd6361..5740158 100644 --- a/lib/services/worldTime.dart +++ b/lib/services/worldTime.dart @@ -40,7 +40,7 @@ class WorldTime { now = now.add(Duration(hours: offsetHours, minutes: offsetMinute)); - time = '${now.toString()} 🧭'; //adding actual time to the time varriable + time = now.toString(); //adding actual time to the time varriable } catch (e) { print('this is a error $e'); From fa531279186de52226e3600356565f57957e93a6 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:15:38 +0530 Subject: [PATCH 7/8] Setting date as a readble format --- lib/pages/home.dart | 62 +++++++++++++++++++++++-------------- lib/pages/loading.dart | 9 ++++-- lib/services/worldTime.dart | 6 ++-- pubspec.lock | 9 +++++- pubspec.yaml | 1 + 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/lib/pages/home.dart b/lib/pages/home.dart index cc52450..e7478dc 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -6,45 +6,59 @@ class Home extends StatefulWidget { } class _HomeState extends State { - - Map data = {}; + Map data = {}; @override Widget build(BuildContext context) { + data = ModalRoute.of(context) + .settings + .arguments; //receiving the data from different route. + print(data); - data = ModalRoute.of(context).settings.arguments; //receiving the data from different route. - print(data); - return Scaffold( - appBar: AppBar(title: Text('Home')), + //appBar: AppBar(title: Text('Home')), body: SafeArea( + child: Padding( + padding: const EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0), + child: Center( child: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - Center( - child: Text( - '${data['time']}', - style: TextStyle(fontSize: 20.5, color: Colors.red), + Text( + '${data['time']}', + style: TextStyle( + fontSize: 30.5, + color: Colors.green, + fontFamily: 'ubuntu', + fontWeight: FontWeight.bold, + ), + ), + SizedBox( + height: 20.0, + ), + Text( + data['location'], + style: TextStyle( + fontSize: 25.0, + fontFamily: 'ubuntu', ), ), - FlatButton.icon( + SizedBox(height: 20.0), + RaisedButton.icon( + elevation: 0.0, onPressed: () { Navigator.pushNamed(context, '/locate'); }, - icon: Icon(Icons.edit_location), - label: Text('choose your current location'), + icon: Icon(Icons.location_city), + label: Text('location'), + color: Colors.greenAccent[100], + splashColor: Colors.greenAccent[200], + hoverColor: Colors.red, + textColor: Colors.green[800], ), - FlatButton( - onPressed: () { - Navigator.pushNamed(context, '/load'); - }, - child: Icon( - Icons.get_app, - color: Colors.red, - semanticLabel: 'Get DAta', - )) ], ), - )); + ), + ), + )); } } diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index 5127999..d6f2002 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -29,10 +29,15 @@ class _LoadingState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text('Loading')), body: SafeArea( child: Center( - child: Text('loading...'), + child: Text('Loading...☁☁☁', + style: TextStyle( + fontSize:25.0, + fontFamily:'ubuntu', + color:Colors.green + ), + ), ), )); } diff --git a/lib/services/worldTime.dart b/lib/services/worldTime.dart index 5740158..9b528a3 100644 --- a/lib/services/worldTime.dart +++ b/lib/services/worldTime.dart @@ -1,6 +1,6 @@ import 'package:http/http.dart'; import 'dart:convert'; - +import 'package:intl/intl.dart'; class WorldTime { String location; //ui friendly location String flag; //custom image @@ -39,8 +39,8 @@ class WorldTime { //adding offset hours and minutes to the datetime now = now.add(Duration(hours: offsetHours, minutes: offsetMinute)); - - time = now.toString(); //adding actual time to the time varriable + time = DateFormat.jm().format(now); //using 'intl' class to define date + } catch (e) { print('this is a error $e'); diff --git a/pubspec.lock b/pubspec.lock index 2b8842a..cea67cc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -95,6 +95,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.4" + intl: + dependency: "direct dev" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: @@ -206,4 +213,4 @@ packages: source: hosted version: "3.5.0" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.5.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index e6b16e8..8f658ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dev_dependencies: flutter_test: sdk: flutter http: ^0.12.0+4 + intl: ^0.16.1 # For information on the generic Dart part of this file, see the From 67eb8912677dcb1dd32e15497372c482cbe25a86 Mon Sep 17 00:00:00 2001 From: Souvik Mandal <58888934+souvik362@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:39:33 +0530 Subject: [PATCH 8/8] Adding spinners from SpinKit Package --- lib/pages/loading.dart | 36 ++++++++++++++++-------------------- pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/pages/loading.dart b/lib/pages/loading.dart index d6f2002..72ec496 100644 --- a/lib/pages/loading.dart +++ b/lib/pages/loading.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:my_new_app/services/worldTime.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; class Loading extends StatefulWidget { @override @@ -7,38 +8,33 @@ class Loading extends StatefulWidget { } class _LoadingState extends State { - - - void setTime() async { - WorldTime currentTime = WorldTime(location:'kolkata', url:'Asia/Kolkata',flag: 'get.png'); + WorldTime currentTime = + WorldTime(location: 'kolkata', url: 'Asia/Kolkata', flag: 'get.png'); await currentTime.getTime(); - Navigator.pushReplacementNamed(context, '/home',arguments: { - 'location':currentTime.location, - 'flag':currentTime.flag, - 'time':currentTime.time - }); //sending data to different route using arguments. + Navigator.pushReplacementNamed(context, '/home',arguments: { + 'location':currentTime.location, + 'flag':currentTime.flag, + 'time':currentTime.time + }); //sending data to different route using arguments. } @override void initState() { super.initState(); setTime(); - } + } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( - child: Center( - child: Text('Loading...☁☁☁', - style: TextStyle( - fontSize:25.0, - fontFamily:'ubuntu', - color:Colors.green - ), - ), - ), - )); + child: Center( + child: SpinKitChasingDots( + color: Colors.green, + size: 70.0, + ), + ), + )); } } diff --git a/pubspec.lock b/pubspec.lock index cea67cc..9e345ab 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -69,6 +69,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_spinkit: + dependency: "direct dev" + description: + name: flutter_spinkit + url: "https://pub.dartlang.org" + source: hosted + version: "4.1.2+1" flutter_test: dependency: "direct dev" description: flutter @@ -214,3 +221,4 @@ packages: version: "3.5.0" sdks: dart: ">=2.5.0 <3.0.0" + flutter: ">=0.1.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8f658ab..b2e9f03 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dev_dependencies: sdk: flutter http: ^0.12.0+4 intl: ^0.16.1 + flutter_spinkit: "^4.1.2" # For information on the generic Dart part of this file, see the