From cf14a85eaf97137aa3327293ca3f0a79cca1d138 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Thu, 19 Jan 2023 16:39:25 +0530 Subject: [PATCH] update for permission and destination ordering --- .../destination/destination_controller.dart | 19 +++++++ lib/pages/permission/permission.dart | 54 ++++++++++++++++--- lib/utils/database_helper.dart | 29 ++++++++++ lib/widgets/destination_widget.dart | 35 ++---------- pubspec.yaml | 2 +- 5 files changed, 99 insertions(+), 40 deletions(-) diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index fde22f1..f552b07 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -643,6 +643,25 @@ class DestinationController extends GetxController { } + void toggleSelection(Destination dest) async { + DatabaseHelper db = DatabaseHelper.instance; + await db.toggleSelecttion(dest); + destinations.clear(); + db.getDestinations().then((value){ + destinationCount.value = 0; + currentSelectedDestinations.clear(); + for(Destination d in value){ + //print("------ destination controller populating destination-------- ${d.checkedin}-------- :::::"); + //print("-----populated----- ${d.toMap()}"); + if(d.selected!){ + currentSelectedDestinations.add(d); + } + destinations.add(d); + } + destinationCount.value = destinations.length; + }); + } + void PopulateDestinations(){ print("--------- destination controller populsting destinations ----------- ::::::"); diff --git a/lib/pages/permission/permission.dart b/lib/pages/permission/permission.dart index 0792e7c..307e1ac 100644 --- a/lib/pages/permission/permission.dart +++ b/lib/pages/permission/permission.dart @@ -11,6 +11,7 @@ class PermissionHandlerScreen extends StatefulWidget { } class _PermissionHandlerScreenState extends State { + Future _showMyDialog() async { return showDialog( @@ -45,10 +46,15 @@ class _PermissionHandlerScreenState extends State { void initState() { // TODO: implement initState super.initState(); - permissionServiceCall(); + + //permissionServiceCall(); } - permissionServiceCall() async { + Future checkLocationPermission() async { + return await Permission.location.status; + } + + permissionServiceCall() async { await permissionServices().then( (value) { if (value != null) { @@ -106,11 +112,45 @@ class _PermissionHandlerScreenState extends State { @override Widget build(BuildContext context) { - return Container( - color: Colors.white, - child: Center( - child: Text(""), - ), + var status = Permission.location.status.then((value){ + if(value.isGranted == false){ + Future.delayed(Duration.zero, () => showAlert(context)); + } + else { + Get.toNamed(AppPages.TRAVEL); + } + }); + return Scaffold( + body: Container( + child: Text(""), + ), + ); + } + + void showAlert(BuildContext context) { + showDialog( + context: context, + builder: (_) => AlertDialog( + title: const Text('ロケーション許可'), + content: SingleChildScrollView( + child: ListBody( + children: const [ + Text( 'このアプリでは、位置情報の収集を行います。'), + Text('岐阜ナビアプリではチェックポイントの自動チェックインの機能を可能にするために、現在地のデータが収集されます。アプリを閉じている時や、使用していないときにも収集されます。位置情報は、個人を特定できない統計的な情報として、ユーザーの個人情報とは一切結びつかない形で送信されます。お知らせの配信、位置情報の利用を許可しない場合は、この後表示されるダイアログで「許可しない」を選択してください。'), + ], + ), + ), + actions: [ + TextButton( + child: const Text('わかった'), + onPressed: () { + permissionServiceCall(); + }, + ), + ], + ) ); } + + } \ No newline at end of file diff --git a/lib/utils/database_helper.dart b/lib/utils/database_helper.dart index 92cd348..b621957 100644 --- a/lib/utils/database_helper.dart +++ b/lib/utils/database_helper.dart @@ -98,6 +98,35 @@ class DatabaseHelper{ return roglist; } + Future clearSelection() async { + Database db = await instance.database; + Map row_clear = { + "selected": false + }; + return await db.update( + "destination", + row_clear + ); + } + + Future toggleSelecttion(Destination dest) async { + Database db = await instance.database; + + bool val = !dest.selected!; + Map row_target = { + "selected": val + }; + + await clearSelection(); + + return await db.update( + "destination", + row_target, + where: 'location_id = ?', + whereArgs: [dest.location_id!] + ); + } + Future deleteRogaining(int id) async { Database db = await instance.database; var rog = await db.delete('rog', where: "id = ${id}"); diff --git a/lib/widgets/destination_widget.dart b/lib/widgets/destination_widget.dart index 59fb33b..bd5065f 100644 --- a/lib/widgets/destination_widget.dart +++ b/lib/widgets/destination_widget.dart @@ -8,6 +8,7 @@ import 'package:rogapp/utils/const.dart'; import 'package:rogapp/utils/database_helper.dart'; import 'package:rogapp/widgets/bottom_sheet_new.dart'; import 'package:rogapp/widgets/bottom_sheet_widget.dart'; +import 'package:sqflite/sqlite_api.dart'; import 'package:timeline_tile/timeline_tile.dart'; class DestinationWidget extends StatelessWidget { @@ -176,7 +177,7 @@ class DestinationWidget extends StatelessWidget { onTap: () async { { Destination? fs = destinationController.destinations[index]; - print("----fsf-----${fs.location_id}"); + print("----fsf-----${index}"); if(fs != null){ if(indexController.currentDestinationFeature.isNotEmpty) { @@ -194,37 +195,7 @@ class DestinationWidget extends StatelessWidget { }; }, onLongPress: (){ - - for(Destination d in destinationController.destinations){ - if(destinationController.currentSelectedDestinations.length > 0){ - if(destinationController.currentSelectedDestinations[0].location_id == destinationController.destinations[index].location_id){ - destinationController.currentSelectedDestinations.clear(); - print("---- found ----"); - destinationController.PopulateDestinations(); - return; - } - } - } - - destinationController.currentSelectedDestinations.clear(); - destinationController.currentSelectedDestinations.add(destinationController.destinations[index]); - - // Destination? match_element = null; - // destinationController.currentSelectedDestinations.forEach((element) { - // if(element.location_id == destinationController.destinations[index].location_id){ - // match_element = element; - // return; - // } - // }); - - // if(match_element != null){ - // destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]); - // } - // //destinationController.currentSelectedDestinations.clear(); - // destinationController.currentSelectedDestinations.add(destinationController.destinations[index]); - - destinationController.PopulateDestinations(); - + destinationController.toggleSelection(destinationController.destinations[index]); }, selectedTileColor: Colors.amberAccent, selected:destinationController.destinations[index].selected!, diff --git a/pubspec.yaml b/pubspec.yaml index 5c6f759..f6db799 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.2+2 +version: 1.0.3+3 environment: sdk: ">=2.16.0 <3.0.0"