update new features and flutter 3.13

This commit is contained in:
Mohamed Nouffer
2023-09-04 22:46:53 +05:30
parent 2ab96cc3d0
commit 3f157d7ddf
22 changed files with 2160 additions and 1703 deletions

View File

@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:get/get.dart';
@ -6,33 +5,32 @@ import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_binding.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/utils/string_values.dart';
import 'package:is_lock_screen/is_lock_screen.dart';
// import 'package:is_lock_screen/is_lock_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
FlutterMapTileCaching.initialise(await RootDirectory.normalCache);
await FlutterMapTileCaching.initialise();
final StoreDirectory instanceA = FMTC.instance('OpenStreetMap (A)');
await instanceA.manage.createAsync();
await instanceA.metadata.addAsync(
key: 'sourceURL',
value: 'https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png',
);
await instanceA.metadata.addAsync(
key: 'validDuration',
value: '14',
);
await instanceA.metadata.addAsync(
key: 'behaviour',
value: 'cacheFirst',
);
await instanceA.manage.createAsync();
await instanceA.metadata.addAsync(
key: 'sourceURL',
value: 'https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png',
);
await instanceA.metadata.addAsync(
key: 'validDuration',
value: '14',
);
await instanceA.metadata.addAsync(
key: 'behaviour',
value: 'cacheFirst',
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
@ -44,22 +42,38 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addObserver(this);
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive) {
print('app inactive, is lock screen: ${await isLockScreen()}');
} else if (state == AppLifecycleState.resumed) {
DestinationController destinationController = Get.find<DestinationController>();
destinationController.initGPS();
print('app resumed');
}
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
print("RESUMED");
DestinationController destinationController = Get.find<DestinationController>();
destinationController.initGPS();
break;
case AppLifecycleState.inactive:
print("INACTIVE");
break;
case AppLifecycleState.paused:
print("PAUSED");
break;
case AppLifecycleState.detached:
print("DETACHED");
break;
case AppLifecycleState.hidden:
print("DETACHED");
break;
}
}
@override
Widget build(BuildContext context) {
@ -70,8 +84,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
fallbackLocale: const Locale('en', 'US'),
title: 'ROGAINING',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
colorScheme:
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 36, 135, 221)),
useMaterial3: true,
),
debugShowCheckedModeBanner: false,
defaultTransition: Transition.cupertino,

View File

@ -112,7 +112,7 @@ class ChangePasswordPage extends StatelessWidget {
)
),
const SizedBox(height: 20,),
Row(
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,65 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/utils/database_helper.dart';
class HistoryPage extends StatefulWidget {
const HistoryPage({super.key});
@override
State<HistoryPage> createState() => _HistoryPageState();
}
class _HistoryPageState extends State<HistoryPage> {
DatabaseHelper db = DatabaseHelper.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("History"),
),
body: SingleChildScrollView(
child: Column(
children: [
FutureBuilder(
future: db.getDestinations(),
builder: (BuildContext context,
AsyncSnapshot<List<Destination>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occurred',
style: TextStyle(fontSize: 18),
),
);
} else if (snapshot.hasData) {
final dests = snapshot.data;
if (dests!.length > 0) {
return Center(
child: ListView.builder(itemBuilder:(ctx, index){
return ListTile(
title: Text(dests[index].name?? ""),
subtitle: Text(dests[index].address ?? ""),
leading: dests[0].photos != null ? Image.file(File(dests[0].photos!)) : Container(),
);
}),
);
} else {
return Center(child: Text("No checkin yet"));
}
}
}
else if(snapshot.connectionState == ConnectionState.waiting){
return Center(child: CircularProgressIndicator(),);
}
return Container();
}),
],
),
),
);
}
}

View File

@ -20,6 +20,7 @@ import 'package:rogapp/services/cat_service.dart';
import 'package:rogapp/services/location_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
class IndexController extends GetxController {
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
@ -51,6 +52,8 @@ class IndexController extends GetxController {
MapController mapController = MapController();
MapController rogMapController = MapController();
String? userToken;
var mode = 0.obs;
// master mode, rog or selection
@ -191,50 +194,27 @@ List<LatLng> getLocationsList(){
}
void login(String email, String password, BuildContext context){
AuthService.login(email, password).then((value){
void login(String email, String password, BuildContext context) {
AuthService.login(email, password).then((value) {
print("------- logged in user details ######## $value ###### --------");
if(value.isNotEmpty){
currentUser.clear();
currentUser.add(value);
is_loading.value = false;
Navigator.pop(context);
loadUserDetails();
loadLocationsBound();
cats.clear();
if(currentFeature.isNotEmpty){
getAction();
}
if(currentUser.isNotEmpty){
rog_mode.value = 0 ;
}
else{
rog_mode.value = 1;
}
if(rog_mode.value == 1){
switchPage(AppPages.TRAVEL);
}
else{
switchPage(AppPages.INITIAL);
}
//Get.toNamed(AppPages.INITIAL);
}else{
if (value.isNotEmpty) {
Navigator.pop(context);
print("--------- user details login ----- $value");
changeUser(value);
} else {
is_loading.value = false;
Get.snackbar(
"Failed",
"User login failed, please try again.",
icon: const Icon(Icons.error, size: 40.0, color: Colors.blue),
snackPosition: SnackPosition.TOP,
duration: const Duration(milliseconds: 800),
backgroundColor: Colors.yellow,
//icon:Image(image:AssetImage("assets/images/dora.png"))
);
}
});
}
"Failed",
"User login failed, please try again.",
icon: const Icon(Icons.error, size: 40.0, color: Colors.blue),
snackPosition: SnackPosition.TOP,
duration: const Duration(milliseconds: 800),
backgroundColor: Colors.yellow,
//icon:Image(image:AssetImage("assets/images/dora.png"))
);
}
});
}
void changePassword(String oldpassword, String newpassword, BuildContext context){
String _token = currentUser[0]['token'];
@ -407,6 +387,58 @@ void login(String email, String password, BuildContext context){
}
}
void saveToDevice(String val) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("user_token", val);
}
void changeUser(Map<String, dynamic> value, {bool replace = true}) {
print("---- change user to ${value} -----");
currentUser.clear();
currentUser.add(value);
if(replace){
saveToDevice(currentUser[0]["token"]);
}
is_loading.value = false;
loadUserDetails();
loadLocationsBound();
cats.clear();
if (currentFeature.isNotEmpty) {
getAction();
}
if (currentUser.isNotEmpty) {
rog_mode.value = 0;
} else {
rog_mode.value = 1;
}
if (rog_mode.value == 1) {
switchPage(AppPages.TRAVEL);
} else {
switchPage(AppPages.INITIAL);
}
//Get.toNamed(AppPages.INITIAL);
}
loadUserDetailsForToken(String token) async {
AuthService.userForToken(token).then((value) {
print("----token val-- $value ------");
if(value![0]["user"].isEmpty){
Get.toNamed(AppPages.LOGIN);
return;
}
changeUser(value[0], replace:false);
print("--------- user details ----- $value");
// if (value != null && value.isNotEmpty) {
// bool paid = value[0]["paid"] as bool;
// if (paid) {
// loadCustomAreas();
// }
// }
});
}
void loadCustomAreas(){
customAreas.clear();

View File

@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
@ -8,12 +7,12 @@ import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/widgets/list_widget.dart';
import 'package:rogapp/widgets/map_widget.dart';
class IndexPage extends GetView<IndexController> {
IndexPage({Key? key}) : super(key: key);
final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>();
final DestinationController destinationController =
Get.find<DestinationController>();
@override
Widget build(BuildContext context) {
@ -21,39 +20,47 @@ class IndexPage extends GetView<IndexController> {
onWillPop: () async => false,
child: Scaffold(
drawer: DrawerPage(),
appBar: AppBar(
// automaticallyImplyLeading: false,
// leading: IconButton(
// icon: Icon(Icons.arrow_back_ios),
// onPressed: (){
// indexController.switchPage(AppPages.TRAVEL);
// },
// ),
//automaticallyImplyLeading: false,
title: Text("add_location".tr),
actions: [
IconButton(
onPressed: (){
destinationController.fixMapBound();
},
icon: const Icon(Icons.refresh)
),
InkWell(
onTap: (){
Get.toNamed(AppPages.SEARCH);
},
child: Container(
height: 32,
width: 75,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(25),
),
child: const Center(child: Icon(Icons.search),),
),
appBar: AppBar(
// automaticallyImplyLeading: false,
// leading: IconButton(
// icon: Icon(Icons.arrow_back_ios),
// onPressed: (){
// indexController.switchPage(AppPages.TRAVEL);
// },
// ),
//automaticallyImplyLeading: false,
title: Text("add_location".tr),
actions: [
IconButton(
onPressed: () {
Get.toNamed(AppPages.HISTORY);
},
icon: const Icon(Icons.history)),
IconButton(
onPressed: () {
final tk = indexController.currentUser[0]["token"];
if (tk != null) {
destinationController.fixMapBound(tk);
}
},
icon: const Icon(Icons.refresh)),
InkWell(
onTap: () {
Get.toNamed(AppPages.SEARCH);
},
child: Container(
height: 32,
width: 75,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(25),
),
//CatWidget(indexController: indexController,),
child: const Center(
child: Icon(Icons.search),
),
),
),
//CatWidget(indexController: indexController,),
],
),
bottomNavigationBar: BottomAppBar(
@ -61,49 +68,57 @@ class IndexPage extends GetView<IndexController> {
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
padding:
const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
child: InkWell(
child:
Obx(() =>
destinationController.is_gps_selected == true ?
Padding(
padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
child: InkWell(
child: const Image(image: AssetImage('assets/images/route3_off.png'), width: 35, height: 35,),
onTap: (){
//indexController.switchPage(AppPages.TRAVEL);
},
),
) :
Padding(
padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
child: InkWell(
child: const Image(image: AssetImage('assets/images/route2_on.png'),width: 35, height: 35,),
onTap: (){
//indexController.switchPage(AppPages.TRAVEL);
},
),
)
)
),
child:
Obx(() => destinationController.is_gps_selected == true
? Padding(
padding: const EdgeInsets.only(
right: 10.0, top: 4.0, bottom: 4.0),
child: InkWell(
child: const Image(
image: AssetImage(
'assets/images/route3_off.png'),
width: 35,
height: 35,
),
onTap: () {
//indexController.switchPage(AppPages.TRAVEL);
},
),
)
: Padding(
padding: const EdgeInsets.only(
right: 10.0, top: 4.0, bottom: 4.0),
child: InkWell(
child: const Image(
image: AssetImage(
'assets/images/route2_on.png'),
width: 35,
height: 35,
),
onTap: () {
//indexController.switchPage(AppPages.TRAVEL);
},
),
))),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: (){
onPressed: () {
indexController.toggleMode();
if(indexController.currentCat.isNotEmpty){
print(indexController.currentCat[0].toString());
}
if (indexController.currentCat.isNotEmpty) {
print(indexController.currentCat[0].toString());
}
},
tooltip: 'Increment',
child: Obx(() =>
indexController.mode == 0 ?
const Image(image: AssetImage('assets/images/list2.png'))
:
const Image(image: AssetImage('assets/images/map.png')),
child: Obx(
() => indexController.mode == 0
? const Image(image: AssetImage('assets/images/list2.png'))
: const Image(image: AssetImage('assets/images/map.png')),
),
elevation: 4.0,
),
@ -129,11 +144,11 @@ class IndexPage extends GetView<IndexController> {
// // ),
// child: SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Obx(() =>
// child: Obx(() =>
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// indexController.is_mapController_loaded.value == false ?
// indexController.is_mapController_loaded.value == false ?
// Center(child: CircularProgressIndicator())
// :
// BreadCrumbWidget(mapController: indexController.mapController),
@ -146,7 +161,7 @@ class IndexPage extends GetView<IndexController> {
// // onPressed: (){
// // indexController.currentCat.clear();
// // indexController.loadLocationsBound();
// // },
// // },
// // icon: Icon(Icons.cancel, color: Colors.red,)
// // ) :
// // Container(width: 0, height: 0,)
@ -158,18 +173,15 @@ class IndexPage extends GetView<IndexController> {
// ),
// ),
Expanded(
child: Obx(() =>
indexController.mode == 0 ?
MapWidget() :
const ListWidget(),
)
)
child: Obx(
() => indexController.mode == 0
? MapWidget()
: const ListWidget(),
))
],
),
),
),
);
}
}
}

View File

@ -20,8 +20,8 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('ロケーション許可'),
content: SingleChildScrollView(
title: const Text('ロケーション許可'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text( 'このアプリでは、位置情報の収集を行います。'),
@ -160,8 +160,8 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('無効'),
content: SingleChildScrollView(
title: const Text('無効'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text( '位置情報が無効になっています'),
@ -187,8 +187,8 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('ロケーション許可'),
content: SingleChildScrollView(
title: const Text('ロケーション許可'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text( 'このアプリでは、位置情報の収集を行います。'),

View File

@ -6,6 +6,7 @@ import 'package:rogapp/pages/changepassword/change_password_page.dart';
import 'package:rogapp/pages/city/city_page.dart';
import 'package:rogapp/pages/destination/destination_binding.dart';
import 'package:rogapp/pages/destination/destination_page.dart';
import 'package:rogapp/pages/history/history_page.dart';
import 'package:rogapp/pages/home/home_binding.dart';
import 'package:rogapp/pages/home/home_page.dart';
@ -48,6 +49,7 @@ class AppPages {
static const CHANGE_PASSWORD = Routes.CHANGE_PASSWORD;
static const CAMERA_PAGE = Routes.CAMERA_PAGE;
static const PROGRESS = Routes.PROGRESS;
static const HISTORY = Routes.HISTORY;
static final routes = [
// GetPage(
@ -141,6 +143,10 @@ class AppPages {
GetPage(
name: Routes.PROGRESS,
page: () => const ProgressPage(),
),
GetPage(
name: Routes.HISTORY,
page: () => const HistoryPage(),
)
];
}

View File

@ -24,4 +24,5 @@ abstract class Routes {
static const CHANGE_PASSWORD = '/change_password';
static const CAMERA_PAGE = '/camera_page';
static const PROGRESS = '/progress';
static const HISTORY = '/history';
}

View File

@ -118,6 +118,26 @@ class AuthService{
static Future<List<dynamic>?> userForToken(String token) async {
Map<String, dynamic> cats = {};
String serverUrl = ConstValues.currentServer();
String url = '$serverUrl/api/user/';
print('++++++++$url');
print("---- UserDetails url is $url");
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token $token'
},
);
if (response.statusCode == 200) {
cats = json.decode(utf8.decode(response.bodyBytes));
print("--- eeeeee $cats ----");
}
return [{"user":cats}];
}

File diff suppressed because it is too large Load Diff

View File

@ -369,7 +369,7 @@ class BottomSheetWidget extends StatelessWidget {
],
),
),
Row(
const Row(
children: [
SizedBox(height: 60.0,),
],

View File

@ -113,7 +113,7 @@ class DestinationWidget extends StatelessWidget {
buttonColor: Colors.white,
barrierDismissible: false,
radius: 10,
content: Column(
content: const Column(
children: [
],
),