From 8b20b3f62122fef6acef75e3d06d97abd29b736d Mon Sep 17 00:00:00 2001 From: magicsk Date: Fri, 27 Mar 2020 23:12:32 +0100 Subject: [PATCH] fixed Trip planner --- ios/Flutter/flutter_export_environment.sh | 6 +- lib/NearMe.dart | 109 ++++++++++++++-------- lib/TripPlanner.dart | 14 +-- lib/main.dart | 4 +- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh index 2f7d7c2..32edd47 100644 --- a/ios/Flutter/flutter_export_environment.sh +++ b/ios/Flutter/flutter_export_environment.sh @@ -1,10 +1,10 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=C:\Users\magic_sk\Downloads\dev\flutter" -export "FLUTTER_APPLICATION_PATH=C:\Users\magic_sk\Downloads\dev\mhd_virtual_table" +export "FLUTTER_ROOT=C:\Users\magic_sk\Development\flutter" +export "FLUTTER_APPLICATION_PATH=C:\Users\magic_sk\Development\mhd_virtual_table" export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build\ios" -export "FLUTTER_FRAMEWORK_DIR=C:\Users\magic_sk\Downloads\dev\flutter\bin\cache\artifacts\engine\ios" +export "FLUTTER_FRAMEWORK_DIR=C:\Users\magic_sk\Development\flutter\bin\cache\artifacts\engine\ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1.0.0" diff --git a/lib/NearMe.dart b/lib/NearMe.dart index 2027910..2e18ce5 100644 --- a/lib/NearMe.dart +++ b/lib/NearMe.dart @@ -30,6 +30,7 @@ class _NearMeState extends State { bool _locationStatus = false; bool _networkStatus = false; bool _restricted = false; + bool _error = false; int tableThemeInt; _getprefs() async { @@ -112,13 +113,13 @@ class _NearMeState extends State { nearStops.addAll(_nearStopsFile); print('nearStops loaded'); _getprefs().then((permission) { - _checkLocationStatus().then((status) { - setState(() { - _locationStatus = status; - _gotPermission = permission; - _isLoading = false; - }); + _checkLocationStatus().then((status) { + setState(() { + _locationStatus = status; + _gotPermission = permission; + _isLoading = false; }); + }); }); } }); @@ -133,20 +134,31 @@ class _NearMeState extends State { }); if (status) { fetchNearStops().then((value) { - setState(() { - nearStops.clear(); - nearStops.addAll(value); - _isLoadingNew = false; + print(value.length); + if (value.length == 0) { + print('Unable to fetch!'); + setState(() { + _error = true; _isLoading = false; - getApplicationDocumentsDirectory() - .then((Directory directory) { - File file = - new File(directory.path + "/" + nearStopsFileName); - file.createSync(); - file.writeAsStringSync(json.encode(nearStops)); - print('nearStops saved'); + _isLoadingNew = false; }); - }); + } else { + setState(() { + nearStops.clear(); + nearStops.addAll(value); + _error = false; + _isLoadingNew = false; + _isLoading = false; + getApplicationDocumentsDirectory() + .then((Directory directory) { + File file = + new File(directory.path + "/" + nearStopsFileName); + file.createSync(); + file.writeAsStringSync(json.encode(nearStops)); + print('nearStops saved'); + }); + }); + } }); } else { setState(() { @@ -213,7 +225,7 @@ class _NearMeState extends State { currentLocation.latitude.toString() + '&long=' + currentLocation.longitude.toString() + - '&skin=' + + '&skin=' + tableThemeInt.toString(); var response = await http.get(url); @@ -253,25 +265,42 @@ class _NearMeState extends State { child: _isLoading ? Center() : _locationStatus - ? Scrollbar( - child: ListView.builder( - scrollDirection: Axis.vertical, - itemCount: nearStops.length, - itemBuilder: (context, index) { - return new FlatButton( - child: NearStopRow(nearStops[index]), - onPressed: () { - Navigator.push( - context, - new MaterialPageRoute( - builder: (context) => - new StopWebView( - nearStops[index]))); + ? _error + ? Padding( + padding: EdgeInsets.only(top: 250.0), + child: Center( + child: Column( + children: [ + Icon(Icons.warning, + size: 150.0, + color: Colors.grey[300]), + Text( + 'Currently unavailable, try again later!', + style: TextStyle( + color: Colors.grey[500])) + ], + ), + ), + ) + : Scrollbar( + child: ListView.builder( + scrollDirection: Axis.vertical, + itemCount: nearStops.length, + itemBuilder: (context, index) { + return new FlatButton( + child: NearStopRow(nearStops[index]), + onPressed: () { + Navigator.push( + context, + new MaterialPageRoute( + builder: (context) => + new StopWebView( + nearStops[index]))); + }, + ); }, - ); - }, - ), - ) + ), + ) : Padding( padding: EdgeInsets.only(top: 250.0), child: Center( @@ -280,7 +309,7 @@ class _NearMeState extends State { ? [ Icon( Icons.not_interested, - size: 200.0, + size: 150.0, color: Colors.grey[300], ), Text( @@ -292,7 +321,7 @@ class _NearMeState extends State { : [ Icon( Icons.location_off, - size: 200.0, + size: 150.0, color: Colors.grey[300], ), _gotPermission @@ -331,7 +360,7 @@ class _NearMeState extends State { children: [ Icon( Icons.signal_cellular_off, - size: 200.0, + size: 150.0, color: Colors.grey[300], ), Text( diff --git a/lib/TripPlanner.dart b/lib/TripPlanner.dart index 6930156..521c0b2 100644 --- a/lib/TripPlanner.dart +++ b/lib/TripPlanner.dart @@ -176,7 +176,6 @@ class _TripPlannerState extends State { appBar: AppBar( centerTitle: true, title: Text('Trip planner'), - backgroundColor: primaryColor, actions: [ IconButton( icon: Icon(Icons.more_vert), @@ -191,7 +190,7 @@ class _TripPlannerState extends State { ) ], bottom: PreferredSize( - preferredSize: Size.fromHeight(188.0), + preferredSize: Size.fromHeight(186.0), child: _inputBar(), ), ), @@ -201,7 +200,7 @@ class _TripPlannerState extends State { child: Column( children: [ Padding(padding: EdgeInsets.all(40.0),), - Icon(Icons.search, size: 200.0, color: Colors.grey[300]), + Icon(Icons.search, size: 150.0, color: Colors.grey[300]), Text("Plan your journy via public transport!", style: TextStyle(color: Colors.grey[500])) ], @@ -270,7 +269,7 @@ class _TripPlannerState extends State { : "Train", style: TextStyle( fontWeight: FontWeight.bold, - fontSize: 16.0, + fontSize: 20.0, color: Colors.white))), ), ), @@ -347,7 +346,7 @@ class _TripPlannerState extends State { _inputBar() { return Padding( padding: const EdgeInsets.only( - bottom: 20.0, left: 15.0, right: 15.0, top: 0.0), + bottom: 5.0, left: 15.0, right: 15.0, top: 0.0), child: Column( children: [ Row( @@ -494,10 +493,12 @@ class _TripPlannerState extends State { child: Row( children: [ Flexible( - child: Row( + child: Column( + children: [ FlatButton( padding: EdgeInsets.all(0), + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () { setState(() { arrivalDeparature = false; @@ -523,6 +524,7 @@ class _TripPlannerState extends State { ), FlatButton( padding: EdgeInsets.all(0), + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, onPressed: () { setState(() { arrivalDeparature = true; diff --git a/lib/main.dart b/lib/main.dart index c0494fe..1689b3b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,7 +22,7 @@ import 'widgets/stopList.dart'; import 'locale/locales.dart'; void main() async { - await WidgetsFlutterBinding.ensureInitialized(); + WidgetsFlutterBinding.ensureInitialized(); await PrefService.init(prefix: 'pref_'); runApp(AlertProvider( child: MyApp(), @@ -52,7 +52,7 @@ final _model = ThemeModel( buttonColor: Colors.red, ), customBlackTheme: ThemeData( - primaryColor: primaryColor, //can be black + primaryColor: Colors.black, //can be Colors.grey[90] accentColor: Colors.red, brightness: Brightness.dark, backgroundColor: Colors.black,