mirror of
https://github.com/supanadit/geo-smart-app.git
synced 2024-11-10 10:02:20 +00:00
3ead80b465
Update some Dependencies Logo Added Start and Stop Tracking Button Optimize Code Stable Version
113 lines
3.1 KiB
Dart
113 lines
3.1 KiB
Dart
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/config.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();
|
|
|
|
if (!Config.dynamicHostSetting) {
|
|
_settingBloc.setSetting(new SettingModel(Config.api, null));
|
|
}
|
|
|
|
_settingBloc.subject.listen((settingModel) {
|
|
if (!settingModel.isNullId()) {
|
|
this.id = settingModel.id;
|
|
}
|
|
if (!settingModel.isNullHost()) {
|
|
this.host = settingModel.host;
|
|
}
|
|
|
|
_hostController.text = this.host;
|
|
|
|
if (settingModel.isNullId()) {
|
|
print("Requesting Unique ID");
|
|
_uniqueIDBloc = new UniqueIDBloc(settingModel);
|
|
_uniqueIDBloc.getUniqueID();
|
|
}
|
|
|
|
if (_uniqueIDBloc != null) {
|
|
this._uniqueIDBloc.subject.listen((uniqueId) {
|
|
print("Your Unique ID " + uniqueId.id.toString());
|
|
if (uniqueId.id != null && uniqueId.id != "") {
|
|
if (!settingModel.isNullId()) {
|
|
Navigator.of(context).pushReplacement(new MaterialPageRoute(
|
|
builder: (BuildContext context) => Map(),
|
|
));
|
|
} else {
|
|
this._settingBloc.setSetting(
|
|
new SettingModel(this._hostController.text, uniqueId.id),
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
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, null),
|
|
);
|
|
},
|
|
child: Text("Save"),
|
|
)
|
|
],
|
|
),
|
|
width: 200,
|
|
height: 400,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|