From 3cbc4508498d43637860367db6a9d2f8a7abe6d2 Mon Sep 17 00:00:00 2001 From: Daniel Mgawi Date: Sun, 10 May 2020 02:43:49 +0200 Subject: [PATCH] success-csv export --- .flutter-plugins-dependencies | 2 +- android/app/src/main/AndroidManifest.xml | 21 +- lib/packages.dart | 3 + lib/screens/loginScreen.dart | 173 ++++++----- lib/screens/myHistory.dart | 365 +++++++++++------------ lib/services/path-provider.dart | 19 ++ pubspec.lock | 25 +- pubspec.yaml | 3 + 8 files changed, 319 insertions(+), 292 deletions(-) create mode 100644 lib/services/path-provider.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 4bf94e2..5c8b339 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"firebase_messaging","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.13/","dependencies":[]},{"name":"flutter_barcode_scanner","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_barcode_scanner-0.1.7/","dependencies":[]},{"name":"flutter_keyboard_visibility","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-1.4.1/","dependencies":[]},{"name":"flutter_open_whatsapp","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_open_whatsapp-0.1.2/","dependencies":[]},{"name":"flutter_vibrate","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_vibrate-1.0.0/","dependencies":[]},{"name":"geolocator","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-5.2.1/","dependencies":["location_permissions"]},{"name":"image_picker","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.6+1/","dependencies":[]},{"name":"location_permissions","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-2.0.5/","dependencies":[]},{"name":"path_provider","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/","dependencies":[]},{"name":"share","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/share-0.6.3+6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+3/","dependencies":[]},{"name":"soundpool","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool-1.0.1/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.2/","dependencies":[]}],"android":[{"name":"connectivity","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"firebase_messaging","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.13/","dependencies":[]},{"name":"flutter_barcode_scanner","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_barcode_scanner-0.1.7/","dependencies":[]},{"name":"flutter_keyboard_visibility","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-1.4.1/","dependencies":[]},{"name":"flutter_open_whatsapp","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_open_whatsapp-0.1.2/","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.7/","dependencies":[]},{"name":"flutter_vibrate","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_vibrate-1.0.0/","dependencies":[]},{"name":"geolocator","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-5.2.1/","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/google_api_availability-2.0.4/","dependencies":[]},{"name":"image_picker","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.6+1/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location_permissions","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-2.0.5/","dependencies":[]},{"name":"path_provider","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/","dependencies":[]},{"name":"share","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/share-0.6.3+6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+3/","dependencies":[]},{"name":"soundpool","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool-1.0.1/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.2/","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_macos-0.1.0+2/","dependencies":[]},{"name":"path_provider_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+6/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+4/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+4/","dependencies":[]},{"name":"soundpool_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool_web-1.0.3/","dependencies":[]},{"name":"url_launcher_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+1/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos"]},{"name":"connectivity_macos","dependencies":[]},{"name":"firebase_messaging","dependencies":[]},{"name":"flutter_barcode_scanner","dependencies":[]},{"name":"flutter_keyboard_visibility","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"flutter_open_whatsapp","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"flutter_vibrate","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"share","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"soundpool","dependencies":["soundpool_web"]},{"name":"soundpool_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-08 16:58:16.683776","version":"1.17.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"firebase_messaging","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.13/","dependencies":[]},{"name":"flutter_barcode_scanner","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_barcode_scanner-0.1.7/","dependencies":[]},{"name":"flutter_keyboard_visibility","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-1.4.1/","dependencies":[]},{"name":"flutter_open_whatsapp","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_open_whatsapp-0.1.2/","dependencies":[]},{"name":"flutter_vibrate","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_vibrate-1.0.0/","dependencies":[]},{"name":"geolocator","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-5.2.1/","dependencies":["location_permissions"]},{"name":"image_picker","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.6+1/","dependencies":[]},{"name":"location_permissions","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-2.0.5/","dependencies":[]},{"name":"path_provider","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.0+hotfix.5/","dependencies":[]},{"name":"share","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/share-0.6.3+6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+3/","dependencies":[]},{"name":"soundpool","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool-1.0.1/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.2/","dependencies":[]}],"android":[{"name":"connectivity","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"firebase_messaging","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-6.0.13/","dependencies":[]},{"name":"flutter_barcode_scanner","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_barcode_scanner-0.1.7/","dependencies":[]},{"name":"flutter_keyboard_visibility","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-1.4.1/","dependencies":[]},{"name":"flutter_open_whatsapp","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_open_whatsapp-0.1.2/","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.7/","dependencies":[]},{"name":"flutter_vibrate","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_vibrate-1.0.0/","dependencies":[]},{"name":"geolocator","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-5.2.1/","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/google_api_availability-2.0.4/","dependencies":[]},{"name":"image_picker","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.6+1/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location_permissions","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/location_permissions-2.0.5/","dependencies":[]},{"name":"path_provider","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.7/","dependencies":[]},{"name":"permission_handler","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.0.0+hotfix.5/","dependencies":[]},{"name":"share","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/share-0.6.3+6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6+3/","dependencies":[]},{"name":"soundpool","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool-1.0.1/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.2/","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_macos-0.1.0+2/","dependencies":[]},{"name":"path_provider_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+6/","dependencies":[]},{"name":"sqflite","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+4/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+4/","dependencies":[]},{"name":"soundpool_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/soundpool_web-1.0.3/","dependencies":[]},{"name":"url_launcher_web","path":"/Users/danielmgawi/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+1/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos"]},{"name":"connectivity_macos","dependencies":[]},{"name":"firebase_messaging","dependencies":[]},{"name":"flutter_barcode_scanner","dependencies":[]},{"name":"flutter_keyboard_visibility","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"flutter_open_whatsapp","dependencies":[]},{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"flutter_vibrate","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"share","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"soundpool","dependencies":["soundpool_web"]},{"name":"soundpool_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-05-10 02:02:57.899858","version":"1.17.0"} \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 0841057..1a84192 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + + - - + + - + diff --git a/lib/packages.dart b/lib/packages.dart index ffbde26..88ba1ee 100644 --- a/lib/packages.dart +++ b/lib/packages.dart @@ -29,6 +29,9 @@ export 'package:flutter_open_whatsapp/flutter_open_whatsapp.dart'; export 'package:time_ago_provider/time_ago_provider.dart'; export 'package:flutter_form_builder/flutter_form_builder.dart'; export 'package:flutter_map/flutter_map.dart'; +export 'package:path_provider/path_provider.dart'; +export 'package:csv/csv.dart'; +export 'package:permission_handler/permission_handler.dart'; //Routes export 'package:homeless/routes.dart'; //Contains all named routes diff --git a/lib/screens/loginScreen.dart b/lib/screens/loginScreen.dart index 44fcaa0..800f7fc 100644 --- a/lib/screens/loginScreen.dart +++ b/lib/screens/loginScreen.dart @@ -25,99 +25,96 @@ class _LoginScreenState extends State { Widget build(BuildContext context) { if (!busyView) { return Scaffold( - body: KeyboardAvoider( - child: Center( - child: Form( - key: _formKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Image.asset( - 'assets/images/Logo.png', - height: 200, - ), - // Text( - // "Homeless", - // style: TextStyle(fontWeight: FontWeight.w800, fontSize: 38), - // ), - Container( - width: MediaQuery.of(context).size.width / 1.3, - child: Column( - children: [ - TextFormField( - controller: usernameController, - decoration: InputDecoration(labelText: "Username"), - keyboardType: TextInputType.text, - ), - TextFormField( - controller: passwordController, - decoration: InputDecoration(labelText: "Password"), - validator: (value) { - return value.length < 4 - ? "Password must be at least 4 characters long" - : null; - }, - obscureText: true, - ), - ], - ), - ), - Column( + body: Center( + child: Form( + key: _formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Image.asset( + 'assets/images/Logo.png', + height: 200, + ), + // Text( + // "Homeless", + // style: TextStyle(fontWeight: FontWeight.w800, fontSize: 38), + // ), + Container( + width: MediaQuery.of(context).size.width / 1.3, + child: Column( children: [ - FlatButton( - padding: EdgeInsets.all(15.0), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50.0), - ), - child: Text( - "Sign In".toUpperCase(), - style: TextStyle( - fontFamily: AppTheme.fontName, - fontWeight: FontWeight.w700, - fontSize: 15, - letterSpacing: 1, - color: AppTheme.nearlyWhite, - ), + TextFormField( + controller: usernameController, + decoration: InputDecoration(labelText: "Username"), + keyboardType: TextInputType.text, + ), + TextFormField( + controller: passwordController, + decoration: InputDecoration(labelText: "Password"), + validator: (value) { + return value.length < 4 + ? "Password must be at least 4 characters long" + : null; + }, + obscureText: true, + ), + ], + ), + ), + Column( + children: [ + FlatButton( + padding: EdgeInsets.all(15.0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50.0), + ), + child: Text( + "Sign In".toUpperCase(), + style: TextStyle( + fontFamily: AppTheme.fontName, + fontWeight: FontWeight.w700, + fontSize: 15, + letterSpacing: 1, + color: AppTheme.nearlyWhite, ), - textColor: AppTheme.white, - onPressed: () async { - if (_formKey.currentState.validate()) { - setState(() { - busyView = true; - }); + ), + textColor: AppTheme.white, + onPressed: () async { + if (_formKey.currentState.validate()) { + setState(() { + busyView = true; + }); - _token = await UserRepository.login( - password: passwordController.text.trim(), - username: usernameController.text.trim(), - ).catchError((onError) { - print(onError); - }); + _token = await UserRepository.login( + password: passwordController.text.trim(), + username: usernameController.text.trim(), + ).catchError((onError) { + print(onError); + }); - if (_token != null) { - ShowToast.showToast("Login Successful", context); - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (context) => Dashboard(), - ), - ); - } else { - setState(() { - busyView = false; - }); - ShowToast.showToast("Login Failed", context); - FocusScope.of(context) - .requestFocus(new FocusNode()); - } + if (_token != null) { + ShowToast.showToast("Login Successful", context); + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => Dashboard(), + ), + ); + } else { + setState(() { + busyView = false; + }); + ShowToast.showToast("Login Failed", context); + FocusScope.of(context).requestFocus(new FocusNode()); } - }, - splashColor: AppTheme.nearlyWhite, - color: AppTheme.nearlyBlack, - ), - ], - ) - ], - ), + } + }, + splashColor: AppTheme.nearlyWhite, + color: AppTheme.nearlyBlack, + ), + ], + ) + ], ), ), )); diff --git a/lib/screens/myHistory.dart b/lib/screens/myHistory.dart index 872a6e8..c34f8df 100644 --- a/lib/screens/myHistory.dart +++ b/lib/screens/myHistory.dart @@ -1,7 +1,9 @@ import 'package:homeless/packages.dart'; import 'package:homeless/data/graphqlQueries.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; +import 'package:homeless/services/path-provider.dart'; import 'package:homeless/widgets/loadingNews.dart'; +import 'package:intl/intl.dart'; class MyHistoryScreen extends StatefulWidget { final String id; @@ -20,6 +22,9 @@ class _MyHistoryScreenState extends State { "Homeless App Reporting a transaction: \nRef: $ref, \nDate: $date"); } + PathProvider pathProvider = PathProvider(); + Permission permission; + String member_id = ''; @override @@ -46,6 +51,13 @@ class _MyHistoryScreenState extends State { backgroundColor: AppTheme.chipBackground, resizeToAvoidBottomPadding: false, appBar: AppBar( + actions: [ + Padding( + padding: EdgeInsets.all(10), + child: IconButton( + icon: FaIcon(FontAwesomeIcons.save), onPressed: () {}), + ) + ], titleSpacing: 1.2, centerTitle: false, backgroundColor: AppTheme.chipBackground, @@ -69,6 +81,44 @@ class _MyHistoryScreenState extends State { ), builder: (QueryResult result, {VoidCallback refetch, FetchMore fetchMore}) { + getCsv() async { + List> rows = List>(); + await Permission.storage.request(); + rows.add([ + "member_name", + "scanDate", + "scanTime", + "project", + "address", + "healthcare", + "food", + "accommodation" + ]); + + if (result.data['collection'] != null) { + for (var homelessMember in result.data['collection']) { + List row = List(); + row.add(homelessMember["member_name"]); + row.add(homelessMember["scanDate"]); + row.add(homelessMember["scanTime"]); + row.add(homelessMember["project"]); + row.add(homelessMember["location"]["address"]); + row.add(homelessMember["healthcare"]); + row.add(homelessMember["food"]); + row.add(homelessMember["accommodation"]); + rows.add(row); + } + + if (await Permission.storage.request().isGranted) { + // Either the permission was already granted before or the user just granted it. + File file = await pathProvider.localFile; + + String csv = const ListToCsvConverter().convert(rows); + file.writeAsString(csv); + } + } + } + if (result.loading) { return LoadingNews(); } @@ -100,198 +150,143 @@ class _MyHistoryScreenState extends State { ], ); } else - return ListView.builder( -// separatorBuilder: (BuildContext context, int index) => Divider(), - itemCount: transactions.length, - itemBuilder: (context, index) { - return Container( - margin: EdgeInsets.all(5.0), - padding: EdgeInsets.all(20.0), - width: MediaQuery.of(context).size.width, - decoration: BoxDecoration( - color: AppTheme.white, - borderRadius: BorderRadius.all(Radius.circular(8.0)), + return SingleChildScrollView( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(5.0), + child: FlatButton( + padding: EdgeInsets.all(5.0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50.0), + ), + child: Text( + "Export CSV".toUpperCase(), + style: TextStyle( + fontFamily: AppTheme.fontName, + fontWeight: FontWeight.w700, + fontSize: 9, + letterSpacing: 1, + color: AppTheme.nearlyWhite, + ), + ), + textColor: AppTheme.white, + onPressed: () async { + getCsv().catchError((onError) { + ShowToast.showToast(onError.toString(), context); + }).whenComplete(() => + ShowToast.showToast("Saved File", context)); + }, + splashColor: AppTheme.nearlyWhite, + color: AppTheme.nearlyBlack, + ), ), - child: InkWell( - // onTap: () { - // Navigator.push( - // this.context, - // MaterialPageRoute( - // builder: (context) => NewsArticleScreen( - // content: repositories[index]['content'], - // title: repositories[index]['title'], - // image: responseData['image']['path'], - // posted: repositories[index]['posted'], - // source: repositories[index]['source'], - // meta: responseData['image']['meta']['title'], - // ), - // ), - // ); - // }, - child: Wrap( - direction: Axis.horizontal, - spacing: 15, - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - // ClipRRect( - // borderRadius: BorderRadius.circular(15.0), - // child: Image.network( - // "${responseData['image']['path']}", - // width: 100, - // fit: BoxFit.cover, - // height: 100, - // ), - // ), - SizedBox( + Container( + height: MediaQuery.of(context).size.height, + child: ListView.builder( +// separatorBuilder: (BuildContext context, int index) => Divider(), + itemCount: transactions.length, + itemBuilder: (context, index) { + return Container( + margin: EdgeInsets.all(4.0), + padding: EdgeInsets.all(20.0), width: MediaQuery.of(context).size.width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AutoSizeText( - "${transactions[index]['scanDate']} • ${TimeAgo.getTimeAgo(int.parse(transactions[index]['scanTime']))}", - style: TextStyle( - fontFamily: AppTheme.fontName, - fontWeight: FontWeight.w400, - fontSize: 15, - color: AppTheme.grey, - ), - ), - SizedBox( - height: 10, - ), - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Divider(), - AutoSizeText( - "Benefits Received".toUpperCase(), - style: TextStyle( - fontFamily: AppTheme.fontName, - fontWeight: FontWeight.w700, - fontSize: 15, - letterSpacing: 1, - color: AppTheme.deactivatedText, - ), - ), - SizedBox( - height: 10, - ), - Container( - child: Row( - crossAxisAlignment: - CrossAxisAlignment.center, - mainAxisAlignment: - MainAxisAlignment.spaceAround, - children: [ - transactions[index]['healthcare'] - ? Wrap( - alignment: - WrapAlignment.center, - crossAxisAlignment: - WrapCrossAlignment - .center, - direction: Axis.vertical, - children: [ - FaIcon( - FontAwesomeIcons - .firstAid, - color: AppTheme - .dark_grey), - AutoSizeText("Healthcare") - ], - ) - : Container(), - transactions[index]['food'] - ? Wrap( - alignment: - WrapAlignment.center, - crossAxisAlignment: - WrapCrossAlignment - .center, - direction: Axis.vertical, - children: [ - FaIcon( - FontAwesomeIcons - .utensils, - color: AppTheme - .lightText), - AutoSizeText("Food") - ], - ) - : Container(), - transactions[index]['accommodation'] - ? Wrap( - alignment: - WrapAlignment.center, - crossAxisAlignment: - WrapCrossAlignment - .center, - direction: Axis.vertical, - children: [ - FaIcon( - FontAwesomeIcons.bed, - color: AppTheme - .lightText), - AutoSizeText( - "A place to Stay") - ], - ) - : Container(), - ], - ), - ), - Divider(), - ], - ), - AutoSizeText( - "Transaction Ref: ${transactions[index]['_id']}", - style: TextStyle( - fontFamily: AppTheme.fontName, - fontWeight: FontWeight.w400, - fontSize: 15, - color: AppTheme.grey, - ), - ), - SizedBox( - height: 10, - ), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - RaisedButton.icon( - clipBehavior: Clip.antiAlias, - icon: FaIcon( - FontAwesomeIcons - .exclamationTriangle, - color: Colors.red), - label: Text( - 'Report Transaction', - style: TextStyle( - color: AppTheme.darkerText, + decoration: BoxDecoration( + color: AppTheme.white, + borderRadius: + BorderRadius.all(Radius.circular(8.0)), + ), + child: InkWell( + // onTap: () { + // Navigator.push( + // this.context, + // MaterialPageRoute( + // builder: (context) => NewsArticleScreen( + // content: repositories[index]['content'], + // title: repositories[index]['title'], + // image: responseData['image']['path'], + // posted: repositories[index]['posted'], + // source: repositories[index]['source'], + // meta: responseData['image']['meta']['title'], + // ), + // ), + // ); + // }, + child: Wrap( + direction: Axis.horizontal, + spacing: 1, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + // ClipRRect( + // borderRadius: BorderRadius.circular(15.0), + // child: Image.network( + // "${responseData['image']['path']}", + // width: 100, + // fit: BoxFit.cover, + // height: 100, + // ), + // ), + + SizedBox( + width: MediaQuery.of(context).size.width, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + children: [ + AutoSizeText( + "${transactions[index]['scanDate']} • ${TimeAgo.getTimeAgo(int.parse(transactions[index]['scanTime']))}", + style: TextStyle( + fontFamily: AppTheme.fontName, + fontWeight: FontWeight.w400, + fontSize: 15, + color: AppTheme.grey, + ), + ), + Spacer(), + RaisedButton( + clipBehavior: Clip.antiAlias, + child: Text( + 'Report', + style: TextStyle( + color: Colors.red, + ), + ), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular( + 22.0)), + color: AppTheme.nearlyWhite, + onPressed: () => _launchReport( + ref: transactions[index] + ['_id'], + date: transactions[index] + ['scanDate']), + ), + ], + ), + AutoSizeText( + "Transaction Ref: ${transactions[index]['_id']}", + style: TextStyle( + fontFamily: AppTheme.fontName, + fontWeight: FontWeight.w400, + fontSize: 15, + color: AppTheme.grey, + ), ), - ), - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(22.0)), - color: AppTheme.nearlyWhite, - onPressed: () => _launchReport( - ref: transactions[index]['_id'], - date: transactions[index] - ['scanDate']), + ], ), - ], - ) - ], + ), + ], + ), ), - ), - ], + ); + }, ), ), - ); - }, + ], + ), ); } diff --git a/lib/services/path-provider.dart b/lib/services/path-provider.dart new file mode 100644 index 0000000..c9b3192 --- /dev/null +++ b/lib/services/path-provider.dart @@ -0,0 +1,19 @@ +import 'package:homeless/packages.dart'; +import 'package:intl/intl.dart'; + +class PathProvider { + String filePath; + static var now = DateTime.now(); + var newNow = DateFormat("yyyy-MM-dd").format(now); + + Future get _localPath async { + final directory = await getExternalStorageDirectory(); + return directory.absolute.path; + } + + Future get localFile async { + final path = await _localPath; + filePath = '$path/data$newNow.csv'; + return File('$path/data$newNow.csv').create(); + } +} diff --git a/pubspec.lock b/pubspec.lock index 34897b7..2c73e0f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -232,6 +232,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + csv: + dependency: "direct main" + description: + name: csv + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.3" cupertino_icons: dependency: "direct main" description: @@ -773,12 +780,12 @@ packages: source: hosted version: "0.1.4" path_provider: - dependency: transitive + dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.5" + version: "1.6.7" path_provider_macos: dependency: transitive description: @@ -800,6 +807,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0+hotfix.5" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" petitparser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 8ce7ff7..068614c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,9 @@ dependencies: url_launcher: ^5.2.7 flutter_barcode_scanner: ^0.1.7 # flutter_rave: + path_provider: ^1.6.7 + permission_handler: ^5.0.0+hotfix.5 + csv: ^4.0.3 rich_alert: ^0.1.32 flutter_login: ^1.0.10+1 flutter_svg: ^0.17.4