mirror of
https://github.com/supanadit/geo-smart-app.git
synced 2024-11-21 17:36:21 +00:00
Change to RxDart and Big Changes
This commit is contained in:
parent
ef9e78aa6b
commit
9aa6666d77
@ -1,2 +1,3 @@
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
||||
android.enableR8=true
|
||||
|
BIN
assets/images/server.png
Normal file
BIN
assets/images/server.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
32
lib/bloc/position_bloc.dart
Normal file
32
lib/bloc/position_bloc.dart
Normal file
@ -0,0 +1,32 @@
|
||||
import 'package:geo_app/model/response.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/repository/position_repository.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class PositionBloc {
|
||||
PositionRepository _repository;
|
||||
final PublishSubject<ResponseModel> _subject =
|
||||
PublishSubject<ResponseModel>();
|
||||
|
||||
SettingModel _settingModel;
|
||||
|
||||
PositionBloc(this._settingModel) {
|
||||
this._repository = PositionRepository(this._settingModel);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_subject.close();
|
||||
}
|
||||
|
||||
sendPosition(String lat, String lng) async {
|
||||
ResponseModel response = await _repository.sendPosition(lat, lng);
|
||||
_subject.sink.add(response);
|
||||
}
|
||||
|
||||
stopTracking(String lat, String lng) async {
|
||||
ResponseModel response = await _repository.stopTracking();
|
||||
_subject.sink.add(response);
|
||||
}
|
||||
|
||||
PublishSubject<ResponseModel> get subject => _subject;
|
||||
}
|
38
lib/bloc/setting.dart
Normal file
38
lib/bloc/setting.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
|
||||
class SettingBloc {
|
||||
PublishSubject<SettingModel> _subject;
|
||||
|
||||
final String _host = "host";
|
||||
final String _id = "id";
|
||||
|
||||
SettingBloc() {
|
||||
this._subject = PublishSubject<SettingModel>();
|
||||
}
|
||||
|
||||
Future<SharedPreferences> getSharedPreferences() async {
|
||||
return await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
setSetting(SettingModel setting) async {
|
||||
SharedPreferences sharedPreferences = await this.getSharedPreferences();
|
||||
sharedPreferences.setString(_host, setting.host);
|
||||
sharedPreferences.setString(_id, setting.id);
|
||||
this.getSetting();
|
||||
}
|
||||
|
||||
getSetting() async {
|
||||
SharedPreferences sharedPreferences = await this.getSharedPreferences();
|
||||
_subject.sink.add(new SettingModel(
|
||||
sharedPreferences.getString(_host),
|
||||
));
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_subject.close();
|
||||
}
|
||||
|
||||
PublishSubject<SettingModel> get subject => _subject;
|
||||
}
|
27
lib/bloc/unique_id_bloc.dart
Normal file
27
lib/bloc/unique_id_bloc.dart
Normal file
@ -0,0 +1,27 @@
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/model/unique_id_model.dart';
|
||||
import 'package:geo_app/repository/unique_id_repository.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class UniqueIDBloc {
|
||||
UniqueIDRepository _repository;
|
||||
final PublishSubject<UniqueIDModel> _subject =
|
||||
PublishSubject<UniqueIDModel>();
|
||||
|
||||
SettingModel _settingModel;
|
||||
|
||||
UniqueIDBloc(this._settingModel) {
|
||||
this._repository = UniqueIDRepository(this._settingModel);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_subject.close();
|
||||
}
|
||||
|
||||
getUniqueID() async {
|
||||
UniqueIDModel response = await _repository.getUniqueID();
|
||||
_subject.sink.add(response);
|
||||
}
|
||||
|
||||
PublishSubject<UniqueIDModel> get subject => _subject;
|
||||
}
|
171
lib/component/loader.dart
Normal file
171
lib/component/loader.dart
Normal file
@ -0,0 +1,171 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
|
||||
enum DotType { square, circle, diamond, icon }
|
||||
|
||||
class Loader extends StatefulWidget {
|
||||
final Color dotOneColor;
|
||||
final Color dotTwoColor;
|
||||
final Color dotThreeColor;
|
||||
final Duration duration;
|
||||
final DotType dotType;
|
||||
final Icon dotIcon;
|
||||
|
||||
Loader(
|
||||
{this.dotOneColor = Colors.redAccent,
|
||||
this.dotTwoColor = Colors.green,
|
||||
this.dotThreeColor = Colors.blueAccent,
|
||||
this.duration = const Duration(milliseconds: 1000),
|
||||
this.dotType = DotType.circle,
|
||||
this.dotIcon = const Icon(Icons.blur_on)});
|
||||
|
||||
@override
|
||||
_LoaderState createState() => _LoaderState();
|
||||
}
|
||||
|
||||
class _LoaderState extends State<Loader> with SingleTickerProviderStateMixin {
|
||||
Animation<double> animation_1;
|
||||
Animation<double> animation_2;
|
||||
Animation<double> animation_3;
|
||||
AnimationController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
controller = AnimationController(duration: widget.duration, vsync: this);
|
||||
|
||||
animation_1 = Tween(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Interval(0.0, 0.80, curve: Curves.ease),
|
||||
),
|
||||
);
|
||||
|
||||
animation_2 = Tween(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Interval(0.1, 0.9, curve: Curves.ease),
|
||||
),
|
||||
);
|
||||
|
||||
animation_3 = Tween(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: Interval(0.2, 1.0, curve: Curves.ease),
|
||||
),
|
||||
);
|
||||
|
||||
controller.addListener(() {
|
||||
setState(() {
|
||||
//print(animation_1.value);
|
||||
});
|
||||
});
|
||||
|
||||
controller.repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: new Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
new Transform.translate(
|
||||
offset: Offset(
|
||||
0.0,
|
||||
-30 *
|
||||
(animation_1.value <= 0.50
|
||||
? animation_1.value
|
||||
: 1.0 - animation_1.value),
|
||||
),
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Dot(
|
||||
radius: 10.0,
|
||||
color: widget.dotOneColor,
|
||||
type: widget.dotType,
|
||||
icon: widget.dotIcon,
|
||||
),
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(
|
||||
0.0,
|
||||
-30 *
|
||||
(animation_2.value <= 0.50
|
||||
? animation_2.value
|
||||
: 1.0 - animation_2.value),
|
||||
),
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Dot(
|
||||
radius: 10.0,
|
||||
color: widget.dotTwoColor,
|
||||
type: widget.dotType,
|
||||
icon: widget.dotIcon,
|
||||
),
|
||||
),
|
||||
),
|
||||
Transform.translate(
|
||||
offset: Offset(
|
||||
0.0,
|
||||
-30 *
|
||||
(animation_3.value <= 0.50
|
||||
? animation_3.value
|
||||
: 1.0 - animation_3.value),
|
||||
),
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Dot(
|
||||
radius: 10.0,
|
||||
color: widget.dotThreeColor,
|
||||
type: widget.dotType,
|
||||
icon: widget.dotIcon,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class Dot extends StatelessWidget {
|
||||
final double radius;
|
||||
final Color color;
|
||||
final DotType type;
|
||||
final Icon icon;
|
||||
|
||||
Dot({this.radius, this.color, this.type, this.icon});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Center(
|
||||
child: type == DotType.icon
|
||||
? Icon(
|
||||
icon.icon,
|
||||
color: color,
|
||||
size: 1.3 * radius,
|
||||
)
|
||||
: new Transform.rotate(
|
||||
angle: type == DotType.diamond ? pi / 4 : 0.0,
|
||||
child: Container(
|
||||
width: radius,
|
||||
height: radius,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: type == DotType.circle
|
||||
? BoxShape.circle
|
||||
: BoxShape.rectangle),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
136
lib/main.dart
136
lib/main.dart
@ -1,149 +1,17 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:background_location/background_location.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geo_app/model/position.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:geo_app/page/startup.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Geo Smart App',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// Try running your application with "flutter run". You'll see the
|
||||
// application has a blue toolbar. Then, without quitting the app, try
|
||||
// changing the primarySwatch below to Colors.green and then invoke
|
||||
// "hot reload" (press "r" in the console where you ran "flutter run",
|
||||
// or simply save your changes to "hot reload" in a Flutter IDE).
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// is not restarted.
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: MyHomePage(title: 'Geo Smart App'),
|
||||
home: Startup(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
MyHomePage({Key key, this.title}) : super(key: key);
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
_MyHomePageState createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
Completer<GoogleMapController> _controller = Completer();
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
double altitude = 0.0;
|
||||
double accuracy = 0.0;
|
||||
double bearing = 0.0;
|
||||
double speed = 0.0;
|
||||
String message = "Connecting to Server";
|
||||
bool _finish = false;
|
||||
Position _position;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
BackgroundLocation.startLocationService();
|
||||
message = "Connecting to Server";
|
||||
Position.getPosition().then((position) {
|
||||
setState(() {
|
||||
_position = position;
|
||||
_finish = this._position.isValid();
|
||||
});
|
||||
}, onError: (error) {
|
||||
message = "Something wrong";
|
||||
});
|
||||
}
|
||||
|
||||
static final CameraPosition _kGooglePlex = CameraPosition(
|
||||
target: LatLng(-6.914744, 107.609810),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
GoogleMap(
|
||||
mapType: MapType.normal,
|
||||
initialCameraPosition: _kGooglePlex,
|
||||
myLocationEnabled: true,
|
||||
myLocationButtonEnabled: true,
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
_controller.complete(controller);
|
||||
BackgroundLocation.getLocationUpdates((location) async {
|
||||
setState(() {
|
||||
this.latitude = location.latitude;
|
||||
this.longitude = location.longitude;
|
||||
this.accuracy = location.accuracy;
|
||||
this.altitude = location.altitude;
|
||||
this.bearing = location.bearing;
|
||||
this.speed = location.speed;
|
||||
|
||||
if (this._position != null) {
|
||||
if (this._position.isValid()) {
|
||||
this._position.lat = this.latitude.toString();
|
||||
this._position.lng = this.longitude.toString();
|
||||
this._position.sendPosition();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Make Camera Follow the Marker
|
||||
// final GoogleMapController controller = await _controller.future;
|
||||
// controller.animateCamera(
|
||||
// CameraUpdate.newCameraPosition(
|
||||
// new CameraPosition(
|
||||
// target: LatLng(this.latitude, this.longitude),
|
||||
// zoom: 19.151926040649414,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
});
|
||||
},
|
||||
),
|
||||
Visibility(
|
||||
visible: !_finish,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black26.withOpacity(0.8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
BackgroundLocation.stopLocationService();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:geo_app/config.dart';
|
||||
import 'package:geo_app/model/response.dart';
|
||||
import 'package:geo_app/model/unique_id.dart';
|
||||
import 'package:geo_app/model/unique_id_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@ -41,9 +41,9 @@ class Position {
|
||||
lng: "0.0",
|
||||
);
|
||||
if (spId == null) {
|
||||
final response = await http.get(Config.api + "/unique/id");
|
||||
final response = await http.get(Config.api + "/id/get/unique");
|
||||
if (response.statusCode == 200) {
|
||||
position.id = UniqueId.fromJson(json.decode(response.body)).id;
|
||||
position.id = UniqueIDModel.fromJson(json.decode(response.body)).id;
|
||||
} else {
|
||||
throw Exception("Something Error");
|
||||
}
|
||||
@ -56,14 +56,28 @@ class Position {
|
||||
return id != null;
|
||||
}
|
||||
|
||||
Future<Response> sendPosition() async {
|
||||
Response result;
|
||||
Future<ResponseModel> sendPosition() async {
|
||||
ResponseModel result;
|
||||
final response = await http.post(
|
||||
Config.api + "/set/point",
|
||||
Config.api + "/point/set",
|
||||
body: json.encode(this.toJson()),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
result = Response.fromJson(json.decode(response.body));
|
||||
result = ResponseModel.fromJson(json.decode(response.body));
|
||||
} else {
|
||||
throw Exception("Something Error");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<ResponseModel> stopPosition() async {
|
||||
ResponseModel result;
|
||||
final response = await http.post(
|
||||
Config.api + "/point/unset",
|
||||
body: json.encode(this.toJson()),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
result = ResponseModel.fromJson(json.decode(response.body));
|
||||
} else {
|
||||
throw Exception("Something Error");
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
class Response {
|
||||
class ResponseModel {
|
||||
String status;
|
||||
|
||||
Response({this.status});
|
||||
ResponseModel({this.status});
|
||||
|
||||
Response.fromJson(Map<String, dynamic> json) {
|
||||
ResponseModel.fromJson(Map<String, dynamic> json) {
|
||||
status = json['status'];
|
||||
}
|
||||
|
||||
|
6
lib/model/setting.dart
Normal file
6
lib/model/setting.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class SettingModel {
|
||||
String host = "";
|
||||
String id = "";
|
||||
|
||||
SettingModel(this.host);
|
||||
}
|
@ -1,12 +1,17 @@
|
||||
class UniqueId {
|
||||
class UniqueIDModel {
|
||||
String id;
|
||||
bool error = false;
|
||||
|
||||
UniqueId({this.id});
|
||||
UniqueIDModel({this.id});
|
||||
|
||||
UniqueId.fromJson(Map<String, dynamic> json) {
|
||||
UniqueIDModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
}
|
||||
|
||||
UniqueIDModel.error() {
|
||||
error = true;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
126
lib/page/map.dart
Normal file
126
lib/page/map.dart
Normal file
@ -0,0 +1,126 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:background_location/background_location.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geo_app/bloc/position_bloc.dart';
|
||||
import 'package:geo_app/bloc/setting.dart';
|
||||
import 'package:geo_app/model/position.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart'
|
||||
as bg;
|
||||
|
||||
class Map extends StatefulWidget {
|
||||
Map({Key key, this.title}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
_MapState createState() => _MapState();
|
||||
}
|
||||
|
||||
class _MapState extends State<Map> {
|
||||
Completer<GoogleMapController> _controller = Completer();
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
double altitude = 0.0;
|
||||
double accuracy = 0.0;
|
||||
double bearing = 0.0;
|
||||
double speed = 0.0;
|
||||
Position _position;
|
||||
PositionBloc _positionBloc;
|
||||
SettingBloc _settingBloc;
|
||||
|
||||
String id;
|
||||
String host;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
BackgroundLocation.startLocationService();
|
||||
super.initState();
|
||||
_settingBloc = new SettingBloc();
|
||||
|
||||
_settingBloc.getSetting();
|
||||
|
||||
_settingBloc.subject.listen((settingModel) {
|
||||
this.id = settingModel.id;
|
||||
this.host = settingModel.host;
|
||||
|
||||
if (this.host != null && this.host != "") {
|
||||
setState(() {
|
||||
_positionBloc = new PositionBloc(settingModel);
|
||||
});
|
||||
}
|
||||
});
|
||||
bg.BackgroundGeolocation.onLocation((bg.Location location) {
|
||||
print('[location] - $location');
|
||||
});
|
||||
bg.BackgroundGeolocation.ready(
|
||||
bg.Config(
|
||||
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
|
||||
distanceFilter: 10.0,
|
||||
stopOnTerminate: false,
|
||||
startOnBoot: true,
|
||||
debug: true,
|
||||
logLevel: bg.Config.LOG_LEVEL_VERBOSE),
|
||||
).then((bg.State state) {
|
||||
if (!state.enabled) {
|
||||
bg.BackgroundGeolocation.start();
|
||||
}
|
||||
});
|
||||
BackgroundLocation.getLocationUpdates((location) async {
|
||||
print("Location Update");
|
||||
setState(() {
|
||||
this.latitude = location.latitude;
|
||||
this.longitude = location.longitude;
|
||||
this.accuracy = location.accuracy;
|
||||
this.altitude = location.altitude;
|
||||
this.bearing = location.bearing;
|
||||
this.speed = location.speed;
|
||||
|
||||
if (this._position != null) {
|
||||
if (this._position.isValid()) {
|
||||
print("VALID");
|
||||
if (_positionBloc != null) {
|
||||
print("SEND");
|
||||
_positionBloc.sendPosition(
|
||||
this._position.lat.toString(),
|
||||
this._position.lng.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static final CameraPosition _kGooglePlex = CameraPosition(
|
||||
target: LatLng(-6.914744, 107.609810),
|
||||
zoom: 14.4746,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
GoogleMap(
|
||||
mapType: MapType.normal,
|
||||
initialCameraPosition: _kGooglePlex,
|
||||
myLocationEnabled: true,
|
||||
myLocationButtonEnabled: true,
|
||||
onMapCreated: (GoogleMapController controller) {
|
||||
_controller.complete(controller);
|
||||
print("Map Created");
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
BackgroundLocation.stopLocationService();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
95
lib/page/setting.dart
Normal file
95
lib/page/setting.dart
Normal file
@ -0,0 +1,95 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geo_app/bloc/setting.dart';
|
||||
import 'package:geo_app/bloc/unique_id_bloc.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/page/map.dart';
|
||||
|
||||
class Setting extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _SettingState();
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingState extends State<Setting> {
|
||||
final _hostController = TextEditingController();
|
||||
SettingBloc _settingBloc;
|
||||
UniqueIDBloc _uniqueIDBloc;
|
||||
String id;
|
||||
String host;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_settingBloc = new SettingBloc();
|
||||
|
||||
_settingBloc.getSetting();
|
||||
|
||||
_settingBloc.subject.listen((settingModel) {
|
||||
this.id = settingModel.id;
|
||||
this.host = settingModel.host;
|
||||
|
||||
_hostController.text = this.host;
|
||||
|
||||
if (this.host != null && this.host != "") {
|
||||
_uniqueIDBloc = new UniqueIDBloc(settingModel);
|
||||
_uniqueIDBloc.getUniqueID();
|
||||
}
|
||||
|
||||
if (_uniqueIDBloc != null) {
|
||||
this._uniqueIDBloc.subject.listen((uniqueId) {
|
||||
if (uniqueId.id != null && uniqueId.id != "") {
|
||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||
builder: (BuildContext context) => Map(),
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
child: Center(
|
||||
child: Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/images/server.png"),
|
||||
),
|
||||
),
|
||||
height: 200,
|
||||
),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
TextField(
|
||||
controller: this._hostController,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Host",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
this._settingBloc.setSetting(
|
||||
new SettingModel(this._hostController.text),
|
||||
);
|
||||
},
|
||||
child: Text("Save"),
|
||||
)
|
||||
],
|
||||
),
|
||||
width: 200,
|
||||
height: 400,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
65
lib/page/startup.dart
Normal file
65
lib/page/startup.dart
Normal file
@ -0,0 +1,65 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geo_app/bloc/setting.dart';
|
||||
import 'package:geo_app/component/loader.dart';
|
||||
import 'package:geo_app/page/setting.dart';
|
||||
import 'package:geo_app/page/map.dart';
|
||||
|
||||
class Startup extends StatefulWidget {
|
||||
@override
|
||||
State createState() {
|
||||
return new _StartupState();
|
||||
}
|
||||
}
|
||||
|
||||
class _StartupState extends State<Startup> {
|
||||
SettingBloc _settingBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_settingBloc = new SettingBloc();
|
||||
|
||||
_settingBloc.getSetting();
|
||||
|
||||
_settingBloc.subject.listen((settingModel) {
|
||||
if ((settingModel.host == "" || settingModel.host == null) &&
|
||||
(settingModel.id == "" || settingModel.id == null)) {
|
||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||
builder: (BuildContext context) => Setting(),
|
||||
));
|
||||
} else {
|
||||
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
||||
builder: (BuildContext context) => Map(),
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Loader(),
|
||||
SizedBox(
|
||||
height: 20.0,
|
||||
),
|
||||
Text("Preparing System")
|
||||
],
|
||||
),
|
||||
height: 50,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_settingBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
44
lib/provider/position_provider.dart
Normal file
44
lib/provider/position_provider.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:geo_app/model/position.dart';
|
||||
import 'package:geo_app/model/response.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
|
||||
class PositionProvider {
|
||||
final Dio _dio = Dio();
|
||||
SettingModel _settingModel;
|
||||
|
||||
PositionProvider(this._settingModel);
|
||||
|
||||
Future<ResponseModel> sendPosition(String lat, String lng) async {
|
||||
Position position = new Position(
|
||||
id: this._settingModel.id,
|
||||
type: "user",
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
);
|
||||
try {
|
||||
Response response = await _dio.post(
|
||||
this._settingModel.host + "/point/set",
|
||||
data: position.toJson(),
|
||||
);
|
||||
return ResponseModel.fromJson(response.data);
|
||||
} on DioError catch (e) {
|
||||
return ResponseModel.fromJson(e.response.data);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ResponseModel> stopTracking() async {
|
||||
try {
|
||||
Response response = await _dio.post(
|
||||
this._settingModel.host + "/point/unset",
|
||||
data: {
|
||||
"id": this._settingModel.id,
|
||||
"type": "user",
|
||||
},
|
||||
);
|
||||
return ResponseModel.fromJson(response.data);
|
||||
} on DioError catch (e) {
|
||||
return ResponseModel.fromJson(e.response.data);
|
||||
}
|
||||
}
|
||||
}
|
22
lib/provider/unique_id_provider.dart
Normal file
22
lib/provider/unique_id_provider.dart
Normal file
@ -0,0 +1,22 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/model/unique_id_model.dart';
|
||||
|
||||
class UniqueIDProvider {
|
||||
final String _endpoint = "/id/get/unique";
|
||||
final Dio _dio = Dio();
|
||||
SettingModel _settingModel;
|
||||
|
||||
UniqueIDProvider(this._settingModel);
|
||||
|
||||
Future<UniqueIDModel> getUniqueID() async {
|
||||
try {
|
||||
Response response = await _dio.get(
|
||||
this._settingModel.host + _endpoint,
|
||||
);
|
||||
return UniqueIDModel.fromJson(response.data);
|
||||
} on DioError catch (e) {
|
||||
return UniqueIDModel.error();
|
||||
}
|
||||
}
|
||||
}
|
20
lib/repository/position_repository.dart
Normal file
20
lib/repository/position_repository.dart
Normal file
@ -0,0 +1,20 @@
|
||||
import 'package:geo_app/model/response.dart';
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/provider/position_provider.dart';
|
||||
|
||||
class PositionRepository {
|
||||
PositionProvider _provider;
|
||||
SettingModel _settingModel;
|
||||
|
||||
PositionRepository(this._settingModel) {
|
||||
this._provider = PositionProvider(this._settingModel);
|
||||
}
|
||||
|
||||
Future<ResponseModel> sendPosition(String lat, String lng) {
|
||||
return this._provider.sendPosition(lat, lng);
|
||||
}
|
||||
|
||||
Future<ResponseModel> stopTracking() {
|
||||
return this._provider.stopTracking();
|
||||
}
|
||||
}
|
16
lib/repository/unique_id_repository.dart
Normal file
16
lib/repository/unique_id_repository.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import 'package:geo_app/model/setting.dart';
|
||||
import 'package:geo_app/provider/unique_id_provider.dart';
|
||||
import 'package:geo_app/model/unique_id_model.dart';
|
||||
|
||||
class UniqueIDRepository {
|
||||
UniqueIDProvider _uniqueIDProvider;
|
||||
SettingModel _settingModel;
|
||||
|
||||
UniqueIDRepository(this._settingModel) {
|
||||
this._uniqueIDProvider = UniqueIDProvider(this._settingModel);
|
||||
}
|
||||
|
||||
Future<UniqueIDModel> getUniqueID() {
|
||||
return this._uniqueIDProvider.getUniqueID();
|
||||
}
|
||||
}
|
108
pubspec.lock
108
pubspec.lock
@ -15,6 +15,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.38.5"
|
||||
archive:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.11"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -28,14 +35,21 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
version: "2.4.0"
|
||||
background_fetch:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: background_fetch
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.2"
|
||||
background_location:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: background_location
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.7"
|
||||
version: "0.0.9+1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -49,7 +63,7 @@ packages:
|
||||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "1.2.2"
|
||||
build_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -105,7 +119,7 @@ packages:
|
||||
name: cupertino_icons
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.2"
|
||||
version: "0.1.3"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -113,16 +127,35 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.3"
|
||||
dio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: dio
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_background_geolocation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_background_geolocation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.5"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
front_end:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -143,7 +176,7 @@ packages:
|
||||
name: google_maps_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.21+8"
|
||||
version: "0.5.21+15"
|
||||
html:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -165,6 +198,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
image:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: image
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -206,14 +246,14 @@ packages:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.5"
|
||||
version: "0.12.6"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.7"
|
||||
version: "1.1.8"
|
||||
node_interop:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -255,7 +295,14 @@ packages:
|
||||
name: permission_handler
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.3.0"
|
||||
version: "4.0.0"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: petitparser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -277,13 +324,41 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.5"
|
||||
rxdart:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: rxdart
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.23.1"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.4+3"
|
||||
version: "0.5.6"
|
||||
shared_preferences_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.1+3"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.2+2"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -337,7 +412,7 @@ packages:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.5"
|
||||
version: "0.2.11"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -358,7 +433,14 @@ packages:
|
||||
name: watcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.7+12"
|
||||
version: "0.9.7+13"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.5.0"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -367,5 +449,5 @@ packages:
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
sdks:
|
||||
dart: ">=2.3.0 <3.0.0"
|
||||
flutter: ">=1.6.7 <2.0.0"
|
||||
dart: ">=2.6.0 <3.0.0"
|
||||
flutter: ">=1.12.13+hotfix.4 <2.0.0"
|
||||
|
10
pubspec.yaml
10
pubspec.yaml
@ -24,11 +24,14 @@ dependencies:
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
google_maps_flutter: ^0.5.21+8
|
||||
background_location: ^0.0.7
|
||||
background_location: ^0.0.9+1
|
||||
adhara_socket_io: ^0.4.1
|
||||
http: ^0.12.0+2
|
||||
json_serializable: ^3.2.3
|
||||
shared_preferences: ^0.5.4+3
|
||||
rxdart: ^0.23.1
|
||||
dio: ^3.0.7
|
||||
flutter_background_geolocation: ^1.4.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@ -47,9 +50,8 @@ flutter:
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
assets:
|
||||
- assets/images/server.png
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
||||
|
Loading…
Reference in New Issue
Block a user