mirror of
https://github.com/supanadit/geo-smart-app.git
synced 2024-11-24 11:16:24 +00:00
Guard for System Error
This commit is contained in:
parent
3ead80b465
commit
fa6e4e43ab
@ -4,6 +4,8 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||||
In most cases you can leave this as-is, but you if you want to provide
|
In most cases you can leave this as-is, but you if you want to provide
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class Config {
|
class Config {
|
||||||
static const String api = "http://192.168.1.7:8080";
|
static const String api = "http://192.168.1.7:8080";
|
||||||
static const bool dynamicHostSetting = false;
|
static const bool dynamicHostSetting = true;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class ResponseModel {
|
class ResponseModel {
|
||||||
|
final String errorMessage = "error";
|
||||||
|
|
||||||
String status;
|
String status;
|
||||||
|
|
||||||
ResponseModel({this.status});
|
ResponseModel({this.status});
|
||||||
@ -8,7 +10,11 @@ class ResponseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResponseModel.fromNull() {
|
ResponseModel.fromNull() {
|
||||||
status = "Error";
|
status = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
isError() {
|
||||||
|
return (status == errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:background_location/background_location.dart';
|
import 'package:background_location/background_location.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:geo_app/bloc/position_bloc.dart';
|
import 'package:geo_app/bloc/position_bloc.dart';
|
||||||
import 'package:geo_app/bloc/setting.dart';
|
import 'package:geo_app/bloc/setting.dart';
|
||||||
import 'package:geo_app/model/position.dart';
|
import 'package:geo_app/model/position.dart';
|
||||||
@ -58,14 +59,18 @@ class _MapState extends State<Map> {
|
|||||||
this.host = settingModel.host;
|
this.host = settingModel.host;
|
||||||
|
|
||||||
if (settingModel.isNullId()) {
|
if (settingModel.isNullId()) {
|
||||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
settingPage();
|
||||||
builder: (BuildContext context) => Setting(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.host != null && this.host != "") {
|
if (this.host != null && this.host != "") {
|
||||||
setState(() {
|
setState(() {
|
||||||
_positionBloc = new PositionBloc(settingModel);
|
_positionBloc = new PositionBloc(settingModel);
|
||||||
|
_positionBloc.subject.listen((position) {
|
||||||
|
if (position.isError()) {
|
||||||
|
BackgroundLocation.stopLocationService();
|
||||||
|
settingPage();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -94,23 +99,21 @@ class _MapState extends State<Map> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
BackgroundLocation.stopLocationService();
|
BackgroundLocation.stopLocationService();
|
||||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
settingPage();
|
||||||
builder: (BuildContext context) => Setting(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._position != null) {
|
if (this._position != null) {
|
||||||
if (this._position.isValid()) {
|
if (this._position.isValid()) {
|
||||||
print("Valid Position");
|
|
||||||
if (_positionBloc != null) {
|
if (_positionBloc != null) {
|
||||||
print("Send Position " +
|
|
||||||
this._position.lat.toString() +
|
|
||||||
", " +
|
|
||||||
this._position.lng.toString());
|
|
||||||
_positionBloc.sendPosition(
|
_positionBloc.sendPosition(
|
||||||
this._position.lat.toString(),
|
this._position.lat.toString(),
|
||||||
this._position.lng.toString(),
|
this._position.lng.toString(),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
Fluttertoast.showToast(
|
||||||
|
msg: "Failed to start position service",
|
||||||
|
);
|
||||||
|
settingPage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("Invalid Position");
|
print("Invalid Position");
|
||||||
@ -173,10 +176,18 @@ class _MapState extends State<Map> {
|
|||||||
isTracking = !isTracking;
|
isTracking = !isTracking;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
print("Access Denied");
|
Fluttertoast.showToast(
|
||||||
|
msg: "Make sure you have turn on location services",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settingPage() {
|
||||||
|
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||||
|
builder: (BuildContext context) => Setting(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
print("Disposed");
|
print("Disposed");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:geo_app/bloc/setting.dart';
|
import 'package:geo_app/bloc/setting.dart';
|
||||||
import 'package:geo_app/bloc/unique_id_bloc.dart';
|
import 'package:geo_app/bloc/unique_id_bloc.dart';
|
||||||
import 'package:geo_app/config.dart';
|
import 'package:geo_app/config.dart';
|
||||||
@ -40,32 +41,38 @@ class _SettingState extends State<Setting> {
|
|||||||
|
|
||||||
_hostController.text = this.host;
|
_hostController.text = this.host;
|
||||||
|
|
||||||
if (settingModel.isNullId()) {
|
if (!settingModel.isNullHost()) {
|
||||||
print("Requesting Unique ID");
|
|
||||||
_uniqueIDBloc = new UniqueIDBloc(settingModel);
|
_uniqueIDBloc = new UniqueIDBloc(settingModel);
|
||||||
_uniqueIDBloc.getUniqueID();
|
_uniqueIDBloc.getUniqueID();
|
||||||
}
|
|
||||||
|
|
||||||
if (_uniqueIDBloc != null) {
|
if (_uniqueIDBloc != null) {
|
||||||
this._uniqueIDBloc.subject.listen((uniqueId) {
|
this._uniqueIDBloc.subject.listen((uniqueId) {
|
||||||
print("Your Unique ID " + uniqueId.id.toString());
|
print("Your Unique ID " + uniqueId.id.toString());
|
||||||
if (uniqueId.id != null && uniqueId.id != "") {
|
if (uniqueId.id != null && uniqueId.id != "") {
|
||||||
if (!settingModel.isNullId()) {
|
if (!settingModel.isNullId()) {
|
||||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
mapPage();
|
||||||
builder: (BuildContext context) => Map(),
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
this._settingBloc.setSetting(
|
this._settingBloc.setSetting(
|
||||||
new SettingModel(this._hostController.text, uniqueId.id),
|
new SettingModel(this._hostController.text, uniqueId.id),
|
||||||
);
|
);
|
||||||
|
mapPage();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Fluttertoast.showToast(msg: "Invalid host address");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapPage() {
|
||||||
|
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||||
|
builder: (BuildContext context) => Map(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -92,13 +99,23 @@ class _SettingState extends State<Setting> {
|
|||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
FlatButton(
|
SizedBox(
|
||||||
|
height: 10.0,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
child: FlatButton(
|
||||||
|
color: Colors.blueAccent,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
this._settingBloc.setSetting(
|
this._settingBloc.setSetting(
|
||||||
new SettingModel(this._hostController.text, null),
|
new SettingModel(this._hostController.text, null),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text("Save"),
|
child: Text(
|
||||||
|
"Save",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -23,8 +23,12 @@ class PositionProvider {
|
|||||||
);
|
);
|
||||||
return ResponseModel.fromJson(response.data);
|
return ResponseModel.fromJson(response.data);
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
print(e);
|
print(e.response);
|
||||||
|
if (e.response != null) {
|
||||||
return ResponseModel.fromJson(e.response.data);
|
return ResponseModel.fromJson(e.response.data);
|
||||||
|
} else {
|
||||||
|
return ResponseModel.fromNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +149,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
fluttertoast:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fluttertoast
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.3"
|
||||||
glob:
|
glob:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -31,6 +31,7 @@ dependencies:
|
|||||||
shared_preferences: ^0.5.6
|
shared_preferences: ^0.5.6
|
||||||
rxdart: ^0.23.1
|
rxdart: ^0.23.1
|
||||||
dio: ^3.0.7
|
dio: ^3.0.7
|
||||||
|
fluttertoast: ^3.1.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
Reference in New Issue
Block a user