diff --git a/lib/Components/Buttons/rounded_button.dart b/lib/Components/Buttons/rounded_button.dart new file mode 100644 index 0000000..4005aa6 --- /dev/null +++ b/lib/Components/Buttons/rounded_button.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/constants.dart'; + +class RoundedButton extends StatelessWidget { + final String text; + final Function press; + final Color color, textColor; + final double fontSize; + + const RoundedButton({ + Key key, + this.text, + this.press, + this.color = kBodyTextColor, // TODO + this.textColor = Colors.white, + this.fontSize + }) : super(key: key); + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return FlatButton( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(35.0), + //side: BorderSide(color: kSubTitleColor) + ), + padding: EdgeInsets.symmetric(vertical: 8, horizontal: 25), + color: color, + onPressed: () => { + press() + }, + child: Text( + text, + style: new TextStyle(color: textColor, fontSize: fontSize, fontWeight: FontWeight.w400), + ), + ); + } +} \ No newline at end of file diff --git a/lib/Components/rounded_input_field.dart b/lib/Components/rounded_input_field.dart new file mode 100644 index 0000000..be53d64 --- /dev/null +++ b/lib/Components/rounded_input_field.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/Components/text_field_container.dart'; +import 'package:myhomie_app/constants.dart'; + +class RoundedInputField extends StatelessWidget { + final String hintText; + final IconData icon; + final ValueChanged onChanged; + final String initialValue; + final Color color, textColor, iconColor; + final int maxLength; + const RoundedInputField({ + Key key, + this.hintText, + this.initialValue, + this.icon, + this.color = kTitleTextColor, // TODO + this.textColor = kBodyTextColor, // TODO + this.iconColor = kTitleTextColor, // TODO + this.onChanged, + this.maxLength, // 50 + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return TextFieldContainer( + color: color, + child: TextFormField ( + onChanged: onChanged, + initialValue: initialValue, + cursorColor: textColor, + maxLength: maxLength, + style: TextStyle(fontSize: 20, color: textColor), + decoration: InputDecoration( + icon: icon != null ? Icon( + icon, + color: iconColor, + ): null, + hintText: hintText, + hintStyle: TextStyle(fontSize: 20.0, color: textColor), + border: InputBorder.none, + ) + ), + ); + } +} diff --git a/lib/Components/rounded_password_field.dart b/lib/Components/rounded_password_field.dart new file mode 100644 index 0000000..7bbac63 --- /dev/null +++ b/lib/Components/rounded_password_field.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/Components/text_field_container.dart'; +import 'package:myhomie_app/constants.dart'; + +class RoundedPasswordField extends StatelessWidget { + final ValueChanged onChanged; + const RoundedPasswordField({ + Key key, + this.onChanged, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return TextFieldContainer( + child: TextField( + obscureText: true, + onChanged: onChanged, + cursorColor: kBodyTextColor, // TODO + decoration: InputDecoration( + hintText: "Password", + icon: Icon( + Icons.lock, + color: kBodyTextColor, // TODO + ), + suffixIcon: Icon( + Icons.visibility, + color: kBodyTextColor, // TODO + ), + border: InputBorder.none, + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/Components/text_field_container.dart b/lib/Components/text_field_container.dart new file mode 100644 index 0000000..e97bffc --- /dev/null +++ b/lib/Components/text_field_container.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/constants.dart'; + +class TextFieldContainer extends StatelessWidget { + final Widget child; + final Color color; + const TextFieldContainer({ + Key key, + this.child, + this.color = kBackgroundColor, // TODO + }) : super(key: key); + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return Container( + margin: EdgeInsets.symmetric(vertical: 10), + padding: EdgeInsets.symmetric(horizontal: 20, vertical: 5), + width: size.width * 0.8, + decoration: BoxDecoration( + color: color, + borderRadius: BorderRadius.circular(29), + ), + child: child, + ); + } +} \ No newline at end of file diff --git a/lib/Helpers/DatabaseHelper.dart b/lib/Helpers/DatabaseHelper.dart new file mode 100644 index 0000000..57f0981 --- /dev/null +++ b/lib/Helpers/DatabaseHelper.dart @@ -0,0 +1,107 @@ +import 'dart:convert'; + +import 'package:myhomie_app/Models/homieContext.dart'; +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; + +class DatabaseHelper { + static final _databaseName = "homie_database.db"; + static final _databaseVersion = 1; + + static final table = 'homieAppContext'; + + static final columnId = 'id'; + static final columnUserId = 'deviceId'; + static final columnHomeId = 'homeId'; + static final columnToken = 'token'; + static final columnHost = 'host'; + static final columnLanguage = 'language'; + + DatabaseHelper._privateConstructor(); + static final DatabaseHelper instance = DatabaseHelper._privateConstructor(); + + static Database _database; + Future get database async { + if (_database != null) return _database; + _database = await _initDatabase(); + return _database; + } + + _initDatabase() async { + String path = join(await getDatabasesPath(), _databaseName); + return await openDatabase(path, + version: _databaseVersion, onCreate: _onCreate); + } + + // SQL code to create the database table + Future _onCreate(Database db, int version) async { + await db.execute(''' + CREATE TABLE $table ( + $columnId TEXT NOT NULL PRIMARY KEY, + $columnUserId TEXT NOT NULL, + $columnToken TEXT NOT NULL, + $columnHomeId TEXT NOT NULL, + $columnHost TEXT NOT NULL, + $columnLanguage TEXT NOT NULL + ) + '''); + } + + Future insert(HomieAppContext tabletAppContext) async { + Database db = await instance.database; + + var res = await db.insert(table, tabletAppContext.toMap()); + return res; + } + + Future update(HomieAppContext tabletAppContext) async { + // Get a reference to the database. + final db = await instance.database; + + await db.update( + 'tabletAppContext', + tabletAppContext.toMap(), + where: "id = ?", + whereArgs: [tabletAppContext.id], + ); + } + + Future>> queryAllRows() async { + Database db = await instance.database; + var res = await db.query(table, orderBy: "$columnId DESC"); + return res; + } + + Future delete(String email) async { + Database db = await instance.database; + return await db.delete(table, where: '$columnId = ?', whereArgs: [email]); + } + + Future clearTable() async { + Database db = await instance.database; + return await db.rawQuery("DELETE FROM $table"); + } + + Future getData() async { + HomieAppContext homieAppContext; + + await DatabaseHelper.instance.queryAllRows().then((value) { + value.forEach((element) { + print("DB - CONTEXT --- "); + + homieAppContext = HomieAppContext( + id: element["id"], + userId: element["userId"], + token: element["token"], + host: element["host"], + homeId: element["homeId"], + language: element["language"] + ); + }); + }).catchError((error) { + print(error); + }); + + return homieAppContext; + } +} \ No newline at end of file diff --git a/lib/Helpers/MQTTHelper.dart b/lib/Helpers/MQTTHelper.dart new file mode 100644 index 0000000..01d988b --- /dev/null +++ b/lib/Helpers/MQTTHelper.dart @@ -0,0 +1,121 @@ +import 'dart:convert'; + +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:mqtt_client/mqtt_client.dart'; +import 'package:mqtt_client/mqtt_server_client.dart'; +import 'package:myhomie_app/Models/homieContext.dart'; + + +class MQTTHelper { + MQTTHelper._privateConstructor(); + bool isInstantiated = false; + static final MQTTHelper instance = MQTTHelper._privateConstructor(); + String lastMessage; + + void onConnected(dynamic appContext) { + print('Connected !!!!!!!!!!!! ----------------------------------'); + HomieAppContext homieAppContext = appContext.getContext(); + + homieAppContext.clientMQTT.subscribe("#", MqttQos.atLeastOnce); + + print(homieAppContext.clientMQTT); + + homieAppContext.clientMQTT.updates.listen((List> c) async { + print("IN Received message"); + final MqttPublishMessage message = c[0].payload; + final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message); + print('Received message:$payload from topic: ${c[0].topic}'); + + lastMessage = 'Received message:$payload from topic: ${c[0].topic}'; + + var topic = c[0].topic.split('/')[0]; + + switch(topic) { + case "config": + print('Get message in topic config = $payload'); + break; + case "player": + print('Get message in topic player = $payload'); + // refresh device info + try { + } + catch(e) { + print('Error = $e'); + } + break; + } + }); + } + + // unconnected + void onDisconnected() { + print('Disconnected'); + } + + // subscribe to topic succeeded + void onSubscribed(String topic) { + print('Subscribed topic: $topic'); + } + + // subscribe to topic failed + void onSubscribeFail(String topic) { + print('Failed to subscribe $topic'); + } + + // unsubscribe succeeded + void onUnsubscribed(String topic) { + print('Unsubscribed topic: $topic'); + } + + String getLastMessage() { + print("LAST MESSAAAGE"); + print(lastMessage); + return lastMessage; + } + + Future connect(dynamic appContext) async { + HomieAppContext homieAppContext = appContext.getContext(); + + if (homieAppContext == null) { + homieAppContext = new HomieAppContext(host: '192.168.31.140', userId: 'TODO'); + } // TO DEBUG + + if(homieAppContext.host != null) { + homieAppContext.clientMQTT = MqttServerClient.withPort(homieAppContext.host.replaceAll('http://', ''), 'homie_app_'+homieAppContext.userId, 1883); + isInstantiated = true; + + homieAppContext.clientMQTT.logging(on: false); + homieAppContext.clientMQTT.keepAlivePeriod = 20; + homieAppContext.clientMQTT.onDisconnected = onDisconnected; + homieAppContext.clientMQTT.onConnected = () => onConnected(appContext); + homieAppContext.clientMQTT.onSubscribed = onSubscribed; + + var message = { + "userId": homieAppContext.userId, + "connected": false + }; + + final connMessage = MqttConnectMessage().authenticateAs('user', 'user') // TODO ONLINE + .keepAliveFor(60) + .withWillTopic('player/status') + .withWillMessage(jsonEncode(message)) + .withClientIdentifier('tablet_app_'+homieAppContext.userId) + .startClean() + .withWillQos(MqttQos.atLeastOnce); + + homieAppContext.clientMQTT.connectionMessage = connMessage; + homieAppContext.clientMQTT.autoReconnect = true; + try { + await homieAppContext.clientMQTT.connect(); + + } catch (e) { + print('Exception: $e'); + homieAppContext.clientMQTT.disconnect(); + } + appContext.setContext(homieAppContext); // TODO CLEAN + + return homieAppContext.clientMQTT; + } + return null; + } +} \ No newline at end of file diff --git a/lib/Models/homieContext.dart b/lib/Models/homieContext.dart new file mode 100644 index 0000000..d978acd --- /dev/null +++ b/lib/Models/homieContext.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:mqtt_client/mqtt_server_client.dart'; +import 'dart:convert'; + +import 'package:myhomie_app/client.dart'; + + +class HomieAppContext with ChangeNotifier{ + Client clientAPI; + MqttServerClient clientMQTT; + String id; + String host; + String language; + String userId; + String homeId; + String token; + + + HomieAppContext({this.id, this.userId, this.homeId, this.host, this.language, this.token}); + + Map toMap() { + return { + 'id': id, + 'userId': userId, + 'homeId': homeId, + 'host': host, + 'language': language, + 'token': token, + }; + } + + factory HomieAppContext.fromJson(Map json) { + return new HomieAppContext( + id: json['id'] as String, + userId: json['userId'] as String, + host: json['host'] as String, + homeId: json['homeId'] as String, + language: json['language'] as String, + token: json['token'] as String + ); + } + + // Implement toString to make it easier to see information about + @override + String toString() { + return 'TabletAppContext{id: $id, userId: $userId, homeId: $homeId, language: $language, host: $host}'; + } +} \ No newline at end of file diff --git a/lib/Screens/Debug/DebugPage.dart b/lib/Screens/Debug/DebugPage.dart new file mode 100644 index 0000000..75ab7cf --- /dev/null +++ b/lib/Screens/Debug/DebugPage.dart @@ -0,0 +1,47 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/Helpers/MQTTHelper.dart'; +import 'package:myhomie_app/app_context.dart'; +import 'package:provider/provider.dart'; + +class DebugPage extends StatefulWidget { + DebugPage({Key key}) : super(key: key); + + @override + _DebugPageState createState() => _DebugPageState(); +} + +class _DebugPageState extends State { + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + String lastMessage = "test"; + + //lastMessage = MQTTHelper.instance.getLastMessage() == null ? "rien" : MQTTHelper.instance.getLastMessage(); + + return Scaffold( + appBar: AppBar( + title: Text("Debug TODO"), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Last Message", + ), + Text( + MQTTHelper.instance.getLastMessage() == null ? "rien" : MQTTHelper.instance.getLastMessage(), + style: Theme.of(context).textTheme.headline4, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => {}, + tooltip: 'Increment', + child: Icon(Icons.add), + ), + ); + } +} \ No newline at end of file diff --git a/lib/Screens/Home/HomePage.dart b/lib/Screens/Home/HomePage.dart new file mode 100644 index 0000000..f560220 --- /dev/null +++ b/lib/Screens/Home/HomePage.dart @@ -0,0 +1,155 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter/services.dart'; +import 'package:mqtt_client/mqtt_client.dart'; +import 'package:mqtt_client/mqtt_server_client.dart'; +import 'package:mycoreapi/api.dart'; +import 'package:myhomie_app/Helpers/MQTTHelper.dart'; +import 'package:myhomie_app/Screens/Debug/DebugPage.dart'; +import 'package:myhomie_app/app_context.dart'; +import 'package:myhomie_app/client.dart'; +import 'package:provider/provider.dart'; + +class HomePage extends StatefulWidget { + HomePage({Key key}) : super(key: key); + + @override + _HomePageState createState() => _HomePageState(); +} + +class _HomePageState extends State { + int _counter = 0; + final MqttServerClient client = MqttServerClient.withPort('192.168.31.140', 'flutter_client', 1883); // TODO Add switch button or check online connexion if local broker available + //final MqttServerClient client = MqttServerClient.withPort('myhomie.be', 'flutter_client00', 1883); // TODO ONLINE + + void _incrementCounter() { + setState(() { + _counter++; + + print("client.connectionStatus !!! ==" + client.connectionStatus.toString()); + if (client.connectionStatus.state == MqttConnectionState.connected) { + const pubTopic = 'topic/test'; + final builder = MqttClientPayloadBuilder(); + builder.addString('Hello MQTT'); + client.publishMessage(pubTopic, MqttQos.atLeastOnce, builder.payload); + } + }); + } + + // connection succeeded + void onConnected() { + print('Connected !!!!!!!!!!!! ----------------------------------'); + + client.updates.listen((List> c) { + final MqttPublishMessage message = c[0].payload; + final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message); + print('Received message:$payload from topic: ${c[0].topic}>'); + }); + } + +// unconnected + void onDisconnected() { + print('Disconnected'); + } + +// subscribe to topic succeeded + void onSubscribed(String topic) { + print('Subscribed topic: $topic'); + } + +// subscribe to topic failed + void onSubscribeFail(String topic) { + print('Failed to subscribe $topic'); + } + +// unsubscribe succeeded + void onUnsubscribed(String topic) { + print('Unsubscribed topic: $topic'); + } + + Future connect() async { + client.logging(on: false); + client.keepAlivePeriod = 20; + client.onDisconnected = onDisconnected; + client.onConnected = onConnected; + client.onSubscribed = onSubscribed; + + /// Security context + /*SecurityContext context = new SecurityContext() + ..useCertificateChain('path/to/my_cert.pem') + ..usePrivateKey('path/to/my_key.pem', password: 'key_password') + ..setClientAuthorities('path/to/client.crt', password: 'password');*/ + //client.setProtocolV31(); + //client.secure = true; + //client.securityContext = context; + + final connMessage = MqttConnectMessage() + .authenticateAs('thomas', 'MyCore,1') // TODO ONLINE + /*.keepAliveFor(60) + .withWillTopic('willtopic') + .withWillMessage('Will message')*/ + .withClientIdentifier("TESSST") + .startClean(); + //.withWillQos(MqttQos.atLeastOnce); + //client.secure = true; + client.connectionMessage = connMessage; + client.autoReconnect = true; + try { + await client.connect(); + } catch (e) { + print('Exception: $e'); + client.disconnect(); + } + + client.subscribe("#", MqttQos.atLeastOnce); + + return client; + return null; + } + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + + if (!MQTTHelper.instance.isInstantiated) + { + print("MQTT NOT INSTANTIATED"); + MQTTHelper.instance.connect(appContext); + } + + + return Scaffold( + appBar: AppBar( + title: Text("HomePage TODO"), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return DebugPage(); + }, + ) + ) + }, + tooltip: 'Increment', + child: Icon(Icons.add), + ), + ); + } +} \ No newline at end of file diff --git a/lib/Screens/Login/components/background.dart b/lib/Screens/Login/components/background.dart new file mode 100644 index 0000000..cb5512b --- /dev/null +++ b/lib/Screens/Login/components/background.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; + +class Background extends StatelessWidget { + final Widget child; + const Background({ + Key key, + @required this.child, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return Container( + width: double.infinity, + height: size.height, + child: Stack( + alignment: Alignment.center, + children: [ + /*Positioned( + top: 0, + left: 0, + child: Image.asset( + "assets/images/main_top.png", + width: size.width * 0.35, + ), + ),*/ + /*Positioned( + bottom: 0, + right: 0, + child: Image.asset( + "assets/images/login_bottom.png", + width: size.width * 0.4, + ), + ),*/ + child, + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/Screens/Login/components/body.dart b/lib/Screens/Login/components/body.dart new file mode 100644 index 0000000..81d5c66 --- /dev/null +++ b/lib/Screens/Login/components/body.dart @@ -0,0 +1,188 @@ +import 'package:flutter/material.dart'; +import 'package:mqtt_client/mqtt_server_client.dart'; +import 'package:mycoreapi/api.dart'; +import 'package:myhomie_app/Components/Buttons/rounded_button.dart'; +import 'package:myhomie_app/Components/rounded_input_field.dart'; +import 'package:myhomie_app/Components/rounded_password_field.dart'; +import 'package:myhomie_app/Models/homieContext.dart'; +import 'package:myhomie_app/Screens/Home/HomePage.dart'; +import 'package:myhomie_app/Screens/Login/components/background.dart'; +import 'package:myhomie_app/app_context.dart'; +import 'package:myhomie_app/client.dart'; +import 'package:provider/provider.dart'; + + +class Body extends StatefulWidget { + const Body({ + Key key, + }) : super(key: key); + + @override + State createState() => _BodyState(); +} + +class _BodyState extends State { + final clientAPI = Client('http://192.168.31.140'); // TODO field + + @override + Widget build(BuildContext context) { + final appContext = Provider.of(context); + Size size = MediaQuery.of(context).size; + return Background( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "LOGIN", + style: TextStyle(fontWeight: FontWeight.bold), + ), + SizedBox(height: size.height * 0.03), + /*SvgPicture.asset( + "assets/icons/login.svg", + height: size.height * 0.35, + ),*/ + SizedBox(height: size.height * 0.03), + RoundedInputField( + hintText: "Your Email", + onChanged: (value) {}, + ), + RoundedPasswordField( + onChanged: (value) {}, + ), + RoundedButton( + text: "LOGIN", + press: () async { + // TODO check login etc + var connected = await authenticateTRY(); + if (connected) { + HomieAppContext homieAppContext = new HomieAppContext(); + homieAppContext.host = "http://192.168.31.140";// TODO + homieAppContext.clientMQTT = new MqttServerClient(homieAppContext.host.replaceAll('http://', ''),'tablet_app_'+'TODODODO'); + // homieAppContext.clientAPI = client; // TODO + homieAppContext.userId = "TODO"; // TODO + + setState(() { + appContext.setContext(homieAppContext); + }); + + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (context) { + return HomePage(); + }, + ), + (Route route) => false + ); + } + }, + ), + SizedBox(height: size.height * 0.03), + // TODO + /*AlreadyHaveAnAccountCheck( + press: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + //return SignUpScreen(); + // TODODODO + }, + ), + ); + }, + ),*/ + ], + ), + ), + ); + } + + Future authenticateTRY() async { + print("try auth.. "); + + // if () {} // Add if token exist and not null + not expired + var isConnected = false; + try { + //LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd"); + LoginDTO loginDTO = new LoginDTO(email: "", password: ""); + TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); + print("Token ??"); + print(token); + print(token.accessToken); + setAccessToken(token.accessToken); + isConnected = true; // TODO update context + db + } + catch (e) { + print("error auth"); + } + + return isConnected; + + /*if (!isError) { + UserInfoDetailDTO user = await clientAPI.userApi.userGet("6182c472e20a6dbcfe8fe82c"); + print("user values ??"); + print(user.email); + print(user.id); + + List homes = await clientAPI.homeApi.homeGetAll(user.id); + print("number of homes " + homes.length.toString()); + homes.forEach((element) { + print(element); + }); + + HomeDTO home = homes[0]; // TODO + + List rooms = await clientAPI.roomApi.roomGetAll(home.id); + print("number of rooms " + rooms.length.toString()); + rooms.forEach((element) { + print(element); + }); + + List providers = await clientAPI.providerApi.providerGetAll(home.id); + print("number of providers " + providers.length.toString()); + providers.forEach((element) { + print(element); + }); + + List devices = await clientAPI.deviceApi.deviceGetAll(home.id); + print("number of devices " + devices.length.toString()); + /*devices.forEach((element) { + print(element); + });*/ + + List alarms = await clientAPI.alarmApi.alarmGetAll(home.id); + print("number of alarms " + alarms.length.toString()); + alarms.forEach((element) { + print(element); + }); + + /*List lastEvents = await clientAPI.eventApi.eventGet(home.id); + print("number of events " + lastEvents.length.toString()); + lastEvents.forEach((element) { + print(element); + });*/ + + List automations = await clientAPI.automationApi.automationGetAll(home.id); + print("number of automations " + automations.length.toString()); + automations.forEach((element) { + print(element); + }); + + List groups = await clientAPI.groupApi.groupGetAll(home.id); + print("number of groups " + groups.length.toString()); + groups.forEach((element) { + print(element); + }); + }*/ + } + + void setAccessToken(String accessToken) { + clientAPI.apiApi.authentications.forEach((key, auth) { + if (auth is OAuth) { + auth.accessToken = accessToken; + } + }); + } +} \ No newline at end of file diff --git a/lib/Screens/Login/login_screen.dart b/lib/Screens/Login/login_screen.dart new file mode 100644 index 0000000..4fbc104 --- /dev/null +++ b/lib/Screens/Login/login_screen.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/Screens/Login/components/body.dart'; + +class LoginScreen extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + body: Body(), + ); + } +} \ No newline at end of file diff --git a/lib/app_context.dart b/lib/app_context.dart new file mode 100644 index 0000000..cdbb662 --- /dev/null +++ b/lib/app_context.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:myhomie_app/client.dart'; + +import 'Models/homieContext.dart'; + +class AppContext with ChangeNotifier { + HomieAppContext _homieContext; + Client clientAPI; + + AppContext(this._homieContext); + + getContext() => _homieContext; + setContext(HomieAppContext appContext) async { + _homieContext = appContext; + + notifyListeners(); + } +} diff --git a/lib/client.dart b/lib/client.dart index 409183c..f00d779 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -14,6 +14,15 @@ class Client { UserApi _userApi; UserApi get userApi => _userApi; + HomeApi _homeApi; + HomeApi get homeApi => _homeApi; + + AlarmApi _alarmApi; + AlarmApi get alarmApi => _alarmApi; + + EventApi _eventApi; + EventApi get eventApi => _eventApi; + GroupApi _groupApi; GroupApi get groupApi => _groupApi; @@ -29,13 +38,16 @@ class Client { RoomApi _roomApi; RoomApi get roomApi => _roomApi; - Client() { + Client(String path) { _apiClient = ApiClient( - basePath: "http://192.168.31.140"); + basePath: path); //basePath: "http://localhost:25049"); _tokenApi = TokenApi(_apiClient); _authenticationApi = AuthenticationApi(_apiClient); _userApi = UserApi(_apiClient); + _homeApi = HomeApi(_apiClient); + _alarmApi = AlarmApi(_apiClient); + _eventApi = EventApi(_apiClient); _groupApi = GroupApi(_apiClient); _deviceApi = DeviceApi(_apiClient); _automationApi = AutomationApi(_apiClient); diff --git a/lib/main.dart b/lib/main.dart index eb3dec2..3e35a5c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,19 +1,36 @@ import 'package:flutter/material.dart'; -import 'package:mqtt_client/mqtt_client.dart'; -import 'package:mqtt_client/mqtt_server_client.dart'; -import 'package:mycoreapi/api.dart'; import 'package:myhomie_app/client.dart'; +import 'package:provider/provider.dart'; +import 'Helpers/DatabaseHelper.dart'; +import 'Models/homieContext.dart'; +import 'Screens/Home/HomePage.dart'; +import 'Screens/Login/login_screen.dart'; +import 'app_context.dart'; import 'constants.dart'; -void main() { +void main() async { + WidgetsFlutterBinding.ensureInitialized(); String initialRoute; + HomieAppContext localContext = new HomieAppContext(); + bool isLogged = false; - initialRoute = '/home'; + localContext = await DatabaseHelper.instance.getData(); + + if(localContext != null) { + print("we've got an local db !"); + localContext.clientAPI = new Client(localContext.host); // TODO "http://192.168.31.140" + isLogged = localContext.token != null; // TODO refresh token.. + print(localContext); + } else { + print("NO LOCAL DB !"); + } + + initialRoute = isLogged ? '/home' : '/login'; final MyApp myApp = MyApp( initialRoute: initialRoute, - //context: localContext, + homieAppContext: localContext, ); runApp(myApp); @@ -21,225 +38,39 @@ void main() { class MyApp extends StatefulWidget { final String initialRoute; - //final Context context; - MyApp({this.initialRoute}); + final HomieAppContext homieAppContext; + MyApp({this.initialRoute, this.homieAppContext}); - // This widget is the root of your application. @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { - - @override - Widget build(BuildContext context) { - return MaterialApp( - debugShowCheckedModeBanner: false, - title: 'MyHomie App Demo', - initialRoute: widget.initialRoute, - /*supportedLocales: [ - const Locale('en', 'US'), - //const Locale('fr', 'FR'), - ],*/ - theme: ThemeData( - primarySwatch: Colors.blue, - scaffoldBackgroundColor: kBackgroundColor, - //fontFamily: "Vollkorn", - textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)), - visualDensity: VisualDensity.adaptivePlatformDensity, - ), - routes: { - '/home': (context) => MyHomePage(title: 'MyHomie App Demo Home Page') - } - ); - } -} - -class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); - final String title; - - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - //final MqttServerClient client = MqttServerClient.withPort('192.168.31.140', 'flutter_client', 1883); // TODO Add switch button or check online connexion if local broker available - //final MqttServerClient client = MqttServerClient.withPort('myhomie.be', 'flutter_client00', 1883); // TODO ONLINE - final clientAPI = Client(); - - void _incrementCounter() { - setState(() { - _counter++; - - /*print("client.connectionStatus !!! ==" + client.connectionStatus.toString()); - if (client.connectionStatus.state == MqttConnectionState.connected) { - const pubTopic = 'topic/test'; - final builder = MqttClientPayloadBuilder(); - builder.addString('Hello MQTT'); - client.publishMessage(pubTopic, MqttQos.atLeastOnce, builder.payload); - }*/ - }); - } - - void authenticateTRY() async { - print("try auth.. "); - var isError = true; - try { - LoginDTO loginDTO = new LoginDTO(email: "test@email.be", password: "kljqsdkljqsd"); - TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); - print("Token ??"); - print(token.accessToken); - setAccessToken(token.accessToken); - isError = false; - } - catch (e) { - print("error auth"); - } - - if (!isError) { - UserInfoDetailDTO user = await clientAPI.userApi.userGet("604a33639b4a377a413045b9"); - print("user values ??"); - print(user.email); - print(user.id); - - List rooms = await clientAPI.roomApi.roomGetAll(user.id); - print("number of rooms " + rooms.length.toString()); - rooms.forEach((element) { - print(element); - }); - - List providers = await clientAPI.providerApi.providerGetAll(user.id); - print("number of providers " + providers.length.toString()); - providers.forEach((element) { - print(element); - }); - - List devices = await clientAPI.deviceApi.deviceGetAll(user.id); - print("number of devices " + devices.length.toString()); - /*devices.forEach((element) { - print(element); - });*/ - - List automations = await clientAPI.automationApi.automationGetAll(user.id); - print("number of automations " + automations.length.toString()); - automations.forEach((element) { - print(element); - }); - - List groups = await clientAPI.groupApi.groupGetAll(user.id); - print("number of groups " + groups.length.toString()); - groups.forEach((element) { - print(element); - }); - } - } - - // connection succeeded - void onConnected() { - print('Connected !!!!!!!!!!!! ----------------------------------'); - - /*client.updates.listen((List> c) { - final MqttPublishMessage message = c[0].payload; - final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message); - print('Received message:$payload from topic: ${c[0].topic}>'); - });*/ - } - - void setAccessToken(String accessToken) { - clientAPI.apiApi.authentications.forEach((key, auth) { - if (auth is OAuth) { - auth.accessToken = accessToken; - } - }); - } - -// unconnected - void onDisconnected() { - print('Disconnected'); - } - -// subscribe to topic succeeded - void onSubscribed(String topic) { - print('Subscribed topic: $topic'); - } - -// subscribe to topic failed - void onSubscribeFail(String topic) { - print('Failed to subscribe $topic'); - } - -// unsubscribe succeeded - void onUnsubscribed(String topic) { - print('Unsubscribed topic: $topic'); - } - - Future connect() async { - /*client.logging(on: false); - client.keepAlivePeriod = 20; - client.onDisconnected = onDisconnected; - client.onConnected = onConnected; - client.onSubscribed = onSubscribed;*/ - - /// Security context - /*SecurityContext context = new SecurityContext() - ..useCertificateChain('path/to/my_cert.pem') - ..usePrivateKey('path/to/my_key.pem', password: 'key_password') - ..setClientAuthorities('path/to/client.crt', password: 'password');*/ - //client.setProtocolV31(); - //client.secure = true; - //client.securityContext = context; - - final connMessage = MqttConnectMessage() - .authenticateAs('thomas', 'MyCore,1') // TODO ONLINE - /*.keepAliveFor(60) - .withWillTopic('willtopic') - .withWillMessage('Will message')*/ - .withClientIdentifier("TESSST") - .startClean(); - //.withWillQos(MqttQos.atLeastOnce); - //client.secure = true; - /*client.connectionMessage = connMessage; - client.autoReconnect = true; - try { - await client.connect(); - } catch (e) { - print('Exception: $e'); - client.disconnect(); - } - - client.subscribe("#", MqttQos.atLeastOnce); -*/ - //return client; - return null; - } + //HomieAppContext homieAppContext; @override Widget build(BuildContext context) { - connect(); - return Scaffold( - appBar: AppBar( - title: Text(widget.title), - ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: authenticateTRY, - tooltip: 'Increment', - child: Icon(Icons.add), + return ChangeNotifierProvider( + create: (_) => AppContext(widget.homieAppContext), + child: MaterialApp( + debugShowCheckedModeBanner: false, + title: 'MyHomie App Demo', + initialRoute: widget.initialRoute, + /*supportedLocales: [ + const Locale('en', 'US'), + //const Locale('fr', 'FR'), + ],*/ + theme: ThemeData( + primarySwatch: Colors.blue, + scaffoldBackgroundColor: kBackgroundColor, + //fontFamily: "Vollkorn", + textTheme: TextTheme(bodyText1: TextStyle(color: kBodyTextColor)), + visualDensity: VisualDensity.adaptivePlatformDensity, + ), + routes: { + '/home': (context) => HomePage(), + '/login': (context) => LoginScreen() + } ), ); } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cf98146..8370e57 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -2,11 +2,11 @@ // Generated file. Do not edit. // -// clang-format off - import FlutterMacOS import Foundation +import sqflite func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) } diff --git a/mycore_api/lib/api.dart b/mycore_api/lib/api.dart index c8fdc6a..eff5be1 100644 --- a/mycore_api/lib/api.dart +++ b/mycore_api/lib/api.dart @@ -109,6 +109,7 @@ part 'model/room_create_or_update_detail_dto.dart'; part 'model/room_detail_dto.dart'; part 'model/room_summary_dto.dart'; part 'model/screen_device.dart'; +part 'model/screen_widget.dart'; part 'model/smart_garden_message.dart'; part 'model/smart_printer_message.dart'; part 'model/time_period_alarm.dart'; diff --git a/mycore_api/lib/api/event_api.dart b/mycore_api/lib/api/event_api.dart index 7be6547..bca06f6 100644 --- a/mycore_api/lib/api/event_api.dart +++ b/mycore_api/lib/api/event_api.dart @@ -181,7 +181,7 @@ class EventApi { /// * [OneOfEventType] eventType: /// /// * [OneOfDeviceType] deviceType: - Future eventGetWithHttpInfo(String homeId, { String deviceId, String roomId, int startIndex, int count, DateTime dateStart, DateTime dateEnd, OneOfEventType eventType, OneOfDeviceType deviceType }) async { + Future eventGetWithHttpInfo(String homeId, { String deviceId, String roomId, int startIndex, int count, DateTime dateStart, DateTime dateEnd, EventType eventType, DeviceType deviceType }) async { // Verify required params are set. if (homeId == null) { throw ApiException(HttpStatus.badRequest, 'Missing required param: homeId'); @@ -271,7 +271,7 @@ class EventApi { /// * [OneOfEventType] eventType: /// /// * [OneOfDeviceType] deviceType: - Future> eventGet(String homeId, { String deviceId, String roomId, int startIndex, int count, DateTime dateStart, DateTime dateEnd, OneOfEventType eventType, OneOfDeviceType deviceType }) async { + Future> eventGet(String homeId, { String deviceId, String roomId, int startIndex, int count, DateTime dateStart, DateTime dateEnd, EventType eventType, DeviceType deviceType }) async { final response = await eventGetWithHttpInfo(homeId, deviceId: deviceId, roomId: roomId, startIndex: startIndex, count: count, dateStart: dateStart, dateEnd: dateEnd, eventType: eventType, deviceType: deviceType ); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); diff --git a/mycore_api/lib/model/alarm_mode.dart b/mycore_api/lib/model/alarm_mode.dart index d4d7b05..381cade 100644 --- a/mycore_api/lib/model/alarm_mode.dart +++ b/mycore_api/lib/model/alarm_mode.dart @@ -46,9 +46,9 @@ class AlarmMode { AlarmType type; - OneOfProgrammedMode programmedMode; + ProgrammedMode programmedMode; - OneOfGeolocalizedMode geolocalizedMode; + GeolocalizedMode geolocalizedMode; List triggers; @@ -158,8 +158,8 @@ class AlarmMode { ? null : DateTime.parse(json[r'updatedDate']), type: AlarmType.fromJson(json[r'type']), - programmedMode: OneOfProgrammedMode.fromJson(json[r'programmedMode']), - geolocalizedMode: OneOfGeolocalizedMode.fromJson(json[r'geolocalizedMode']), + programmedMode: ProgrammedMode.fromJson(json[r'programmedMode']), + geolocalizedMode: GeolocalizedMode.fromJson(json[r'geolocalizedMode']), triggers: Trigger.listFromJson(json[r'triggers']), actions: Action.listFromJson(json[r'actions']), devicesIds: json[r'devicesIds'] == null diff --git a/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto.dart b/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto.dart index 9a4c5cc..1fea333 100644 --- a/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto.dart +++ b/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto.dart @@ -49,9 +49,9 @@ class AlarmModeCreateOrUpdateDetailDTO { List actions; - OneOfProgrammedMode programmedMode; + ProgrammedMode programmedMode; - OneOfGeolocalizedMode geolocalizedMode; + GeolocalizedMode geolocalizedMode; @override bool operator ==(Object other) => identical(this, other) || other is AlarmModeCreateOrUpdateDetailDTO && @@ -152,8 +152,8 @@ class AlarmModeCreateOrUpdateDetailDTO { : DateTime.parse(json[r'updatedDate']), triggers: Trigger.listFromJson(json[r'triggers']), actions: Action.listFromJson(json[r'actions']), - programmedMode: OneOfProgrammedMode.fromJson(json[r'programmedMode']), - geolocalizedMode: OneOfGeolocalizedMode.fromJson(json[r'geolocalizedMode']), + programmedMode: ProgrammedMode.fromJson(json[r'programmedMode']), + geolocalizedMode: GeolocalizedMode.fromJson(json[r'geolocalizedMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto_all_of.dart b/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto_all_of.dart index 8360120..e04b206 100644 --- a/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto_all_of.dart +++ b/mycore_api/lib/model/alarm_mode_create_or_update_detail_dto_all_of.dart @@ -22,9 +22,9 @@ class AlarmModeCreateOrUpdateDetailDTOAllOf { List actions; - OneOfProgrammedMode programmedMode; + ProgrammedMode programmedMode; - OneOfGeolocalizedMode geolocalizedMode; + GeolocalizedMode geolocalizedMode; @override bool operator ==(Object other) => identical(this, other) || other is AlarmModeCreateOrUpdateDetailDTOAllOf && @@ -67,8 +67,8 @@ class AlarmModeCreateOrUpdateDetailDTOAllOf { : AlarmModeCreateOrUpdateDetailDTOAllOf( triggers: Trigger.listFromJson(json[r'triggers']), actions: Action.listFromJson(json[r'actions']), - programmedMode: OneOfProgrammedMode.fromJson(json[r'programmedMode']), - geolocalizedMode: OneOfGeolocalizedMode.fromJson(json[r'geolocalizedMode']), + programmedMode: ProgrammedMode.fromJson(json[r'programmedMode']), + geolocalizedMode: GeolocalizedMode.fromJson(json[r'geolocalizedMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/alarm_mode_detail_dto.dart b/mycore_api/lib/model/alarm_mode_detail_dto.dart index 8dafa38..4f15d1b 100644 --- a/mycore_api/lib/model/alarm_mode_detail_dto.dart +++ b/mycore_api/lib/model/alarm_mode_detail_dto.dart @@ -49,9 +49,9 @@ class AlarmModeDetailDTO { List devices; - OneOfProgrammedMode programmedMode; + ProgrammedMode programmedMode; - OneOfGeolocalizedMode geolocalizedMode; + GeolocalizedMode geolocalizedMode; @override bool operator ==(Object other) => identical(this, other) || other is AlarmModeDetailDTO && @@ -152,8 +152,8 @@ class AlarmModeDetailDTO { : DateTime.parse(json[r'updatedDate']), triggers: Trigger.listFromJson(json[r'triggers']), devices: DeviceDetailDTO.listFromJson(json[r'devices']), - programmedMode: OneOfProgrammedMode.fromJson(json[r'programmedMode']), - geolocalizedMode: OneOfGeolocalizedMode.fromJson(json[r'geolocalizedMode']), + programmedMode: ProgrammedMode.fromJson(json[r'programmedMode']), + geolocalizedMode: GeolocalizedMode.fromJson(json[r'geolocalizedMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/alarm_mode_detail_dto_all_of.dart b/mycore_api/lib/model/alarm_mode_detail_dto_all_of.dart index a8b1949..860a99e 100644 --- a/mycore_api/lib/model/alarm_mode_detail_dto_all_of.dart +++ b/mycore_api/lib/model/alarm_mode_detail_dto_all_of.dart @@ -22,9 +22,9 @@ class AlarmModeDetailDTOAllOf { List devices; - OneOfProgrammedMode programmedMode; + ProgrammedMode programmedMode; - OneOfGeolocalizedMode geolocalizedMode; + GeolocalizedMode geolocalizedMode; @override bool operator ==(Object other) => identical(this, other) || other is AlarmModeDetailDTOAllOf && @@ -67,8 +67,8 @@ class AlarmModeDetailDTOAllOf { : AlarmModeDetailDTOAllOf( triggers: Trigger.listFromJson(json[r'triggers']), devices: DeviceDetailDTO.listFromJson(json[r'devices']), - programmedMode: OneOfProgrammedMode.fromJson(json[r'programmedMode']), - geolocalizedMode: OneOfGeolocalizedMode.fromJson(json[r'geolocalizedMode']), + programmedMode: ProgrammedMode.fromJson(json[r'programmedMode']), + geolocalizedMode: GeolocalizedMode.fromJson(json[r'geolocalizedMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/condition.dart b/mycore_api/lib/model/condition.dart index 6c78806..390b350 100644 --- a/mycore_api/lib/model/condition.dart +++ b/mycore_api/lib/model/condition.dart @@ -22,7 +22,7 @@ class Condition { String deviceId; - OneOfAutomationState state; + AutomationState state; String startTime; @@ -82,7 +82,7 @@ class Condition { ? null : Condition( deviceId: json[r'deviceId'], - state: OneOfAutomationState.fromJson(json[r'state']), + state: AutomationState.fromJson(json[r'state']), startTime: json[r'startTime'], endTime: json[r'endTime'], type: ConditionType.fromJson(json[r'type']), diff --git a/mycore_api/lib/model/create_or_update_home_dto.dart b/mycore_api/lib/model/create_or_update_home_dto.dart index 91c5c8d..8bc499e 100644 --- a/mycore_api/lib/model/create_or_update_home_dto.dart +++ b/mycore_api/lib/model/create_or_update_home_dto.dart @@ -30,7 +30,7 @@ class CreateOrUpdateHomeDTO { bool isDefault; - OneOfAlarmModeDTO currentAlarmMode; + AlarmModeDTO currentAlarmMode; DateTime createdDate; @@ -101,7 +101,7 @@ class CreateOrUpdateHomeDTO { name: json[r'name'], isAlarm: json[r'isAlarm'], isDefault: json[r'isDefault'], - currentAlarmMode: OneOfAlarmModeDTO.fromJson(json[r'currentAlarmMode']), + currentAlarmMode: AlarmModeDTO.fromJson(json[r'currentAlarmMode']), createdDate: json[r'createdDate'] == null ? null : DateTime.parse(json[r'createdDate']), diff --git a/mycore_api/lib/model/event_detail_dto.dart b/mycore_api/lib/model/event_detail_dto.dart index 8aebcd6..23d7689 100644 --- a/mycore_api/lib/model/event_detail_dto.dart +++ b/mycore_api/lib/model/event_detail_dto.dart @@ -32,11 +32,11 @@ class EventDetailDTO { String roomId; - OneOfDeviceState deviceState; + DeviceState deviceState; - OneOfAutomationTriggered automationTriggered; + AutomationTriggered automationTriggered; - OneOfAlarmTriggered alarmTriggered; + AlarmTriggered alarmTriggered; @override bool operator ==(Object other) => identical(this, other) || other is EventDetailDTO && @@ -104,9 +104,9 @@ class EventDetailDTO { : DateTime.parse(json[r'date']), type: EventType.fromJson(json[r'type']), roomId: json[r'roomId'], - deviceState: OneOfDeviceState.fromJson(json[r'deviceState']), - automationTriggered: OneOfAutomationTriggered.fromJson(json[r'automationTriggered']), - alarmTriggered: OneOfAlarmTriggered.fromJson(json[r'alarmTriggered']), + deviceState: DeviceState.fromJson(json[r'deviceState']), + automationTriggered: AutomationTriggered.fromJson(json[r'automationTriggered']), + alarmTriggered: AlarmTriggered.fromJson(json[r'alarmTriggered']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/event_detail_dto_all_of.dart b/mycore_api/lib/model/event_detail_dto_all_of.dart index 46464c5..ce7227d 100644 --- a/mycore_api/lib/model/event_detail_dto_all_of.dart +++ b/mycore_api/lib/model/event_detail_dto_all_of.dart @@ -17,11 +17,11 @@ class EventDetailDTOAllOf { this.alarmTriggered, }); - OneOfDeviceState deviceState; + DeviceState deviceState; - OneOfAutomationTriggered automationTriggered; + AutomationTriggered automationTriggered; - OneOfAlarmTriggered alarmTriggered; + AlarmTriggered alarmTriggered; @override bool operator ==(Object other) => identical(this, other) || other is EventDetailDTOAllOf && @@ -57,9 +57,9 @@ class EventDetailDTOAllOf { static EventDetailDTOAllOf fromJson(Map json) => json == null ? null : EventDetailDTOAllOf( - deviceState: OneOfDeviceState.fromJson(json[r'deviceState']), - automationTriggered: OneOfAutomationTriggered.fromJson(json[r'automationTriggered']), - alarmTriggered: OneOfAlarmTriggered.fromJson(json[r'alarmTriggered']), + deviceState: DeviceState.fromJson(json[r'deviceState']), + automationTriggered: AutomationTriggered.fromJson(json[r'automationTriggered']), + alarmTriggered: AlarmTriggered.fromJson(json[r'alarmTriggered']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/geolocalized_mode.dart b/mycore_api/lib/model/geolocalized_mode.dart index 73c14ea..e67fc94 100644 --- a/mycore_api/lib/model/geolocalized_mode.dart +++ b/mycore_api/lib/model/geolocalized_mode.dart @@ -22,9 +22,9 @@ class GeolocalizedMode { String longitude; - OneOfAlarmMode homeMode; + AlarmMode homeMode; - OneOfAlarmMode absentMode; + AlarmMode absentMode; @override bool operator ==(Object other) => identical(this, other) || other is GeolocalizedMode && @@ -67,8 +67,8 @@ class GeolocalizedMode { : GeolocalizedMode( latitude: json[r'latitude'], longitude: json[r'longitude'], - homeMode: OneOfAlarmMode.fromJson(json[r'homeMode']), - absentMode: OneOfAlarmMode.fromJson(json[r'absentMode']), + homeMode: AlarmMode.fromJson(json[r'homeMode']), + absentMode: AlarmMode.fromJson(json[r'absentMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/home_detail_dto.dart b/mycore_api/lib/model/home_detail_dto.dart index 80810de..0c99b6c 100644 --- a/mycore_api/lib/model/home_detail_dto.dart +++ b/mycore_api/lib/model/home_detail_dto.dart @@ -35,7 +35,7 @@ class HomeDetailDTO { bool isDefault; - OneOfAlarmModeDTO currentAlarmMode; + AlarmModeDTO currentAlarmMode; DateTime createdDate; @@ -141,7 +141,7 @@ class HomeDetailDTO { name: json[r'name'], isAlarm: json[r'isAlarm'], isDefault: json[r'isDefault'], - currentAlarmMode: OneOfAlarmModeDTO.fromJson(json[r'currentAlarmMode']), + currentAlarmMode: AlarmModeDTO.fromJson(json[r'currentAlarmMode']), createdDate: json[r'createdDate'] == null ? null : DateTime.parse(json[r'createdDate']), diff --git a/mycore_api/lib/model/home_dto.dart b/mycore_api/lib/model/home_dto.dart index d040356..3c25def 100644 --- a/mycore_api/lib/model/home_dto.dart +++ b/mycore_api/lib/model/home_dto.dart @@ -30,7 +30,7 @@ class HomeDTO { bool isDefault; - OneOfAlarmModeDTO currentAlarmMode; + AlarmModeDTO currentAlarmMode; DateTime createdDate; @@ -101,7 +101,7 @@ class HomeDTO { name: json[r'name'], isAlarm: json[r'isAlarm'], isDefault: json[r'isDefault'], - currentAlarmMode: OneOfAlarmModeDTO.fromJson(json[r'currentAlarmMode']), + currentAlarmMode: AlarmModeDTO.fromJson(json[r'currentAlarmMode']), createdDate: json[r'createdDate'] == null ? null : DateTime.parse(json[r'createdDate']), diff --git a/mycore_api/lib/model/odd_nice.dart b/mycore_api/lib/model/odd_nice.dart index 8d48e9f..71390a4 100644 --- a/mycore_api/lib/model/odd_nice.dart +++ b/mycore_api/lib/model/odd_nice.dart @@ -24,7 +24,7 @@ class OddNice { String homeTeam; - OneOfOddObject odds; + OddObject odds; @override bool operator ==(Object other) => identical(this, other) || other is OddNice && @@ -70,7 +70,7 @@ class OddNice { : (json[r'teams'] as List).cast(), commenceTime: json[r'commence_time'], homeTeam: json[r'home_team'], - odds: OneOfOddObject.fromJson(json[r'odds']), + odds: OddObject.fromJson(json[r'odds']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/mycore_api/lib/model/time_period_alarm.dart b/mycore_api/lib/model/time_period_alarm.dart index a4e67c2..d0f3505 100644 --- a/mycore_api/lib/model/time_period_alarm.dart +++ b/mycore_api/lib/model/time_period_alarm.dart @@ -21,7 +21,7 @@ class TimePeriodAlarm { String end; - OneOfAlarmMode alarmMode; + AlarmMode alarmMode; @override bool operator ==(Object other) => identical(this, other) || other is TimePeriodAlarm && @@ -59,7 +59,7 @@ class TimePeriodAlarm { : TimePeriodAlarm( start: json[r'start'], end: json[r'end'], - alarmMode: OneOfAlarmMode.fromJson(json[r'alarmMode']), + alarmMode: AlarmMode.fromJson(json[r'alarmMode']), ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/pubspec.lock b/pubspec.lock index 7ccda81..26f545a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,14 +21,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -64,6 +64,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + enum_to_string: + dependency: "direct main" + description: + name: enum_to_string + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" event_bus: dependency: transitive description: @@ -88,6 +95,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.dartlang.org" + source: hosted + version: "8.0.8" http: dependency: transitive description: @@ -109,20 +128,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" mqtt_client: dependency: "direct main" description: @@ -137,6 +163,13 @@ packages: relative: true source: path version: "1.0.0" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" path: dependency: transitive description: @@ -151,6 +184,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.0" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" rxdart: dependency: "direct main" description: @@ -170,6 +210,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.1" + sqflite: + dependency: "direct main" + description: + name: sqflite + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0+4" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1+1" stack_trace: dependency: transitive description: @@ -191,6 +245,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + synchronized: + dependency: transitive + description: + name: synchronized + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" term_glyph: dependency: transitive description: @@ -204,7 +265,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.3" typed_data: dependency: transitive description: @@ -220,4 +281,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index f12f867..d5d1264 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,10 @@ dependencies: flutter: sdk: flutter + fluttertoast: + sqflite: + provider: ^5.0.0 + enum_to_string: ^2.0.1 mqtt_client: ^8.1.0 rxdart: 0.22.0 mycoreapi: