mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 00:51:19 +00:00
Debug page from drawer and semi working
This commit is contained in:
parent
c4f2e29b9e
commit
d145689ec3
@ -4,15 +4,15 @@ 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';
|
||||
import 'package:myhomie_app/app_context.dart';
|
||||
|
||||
|
||||
class MQTTHelper {
|
||||
MQTTHelper._privateConstructor();
|
||||
bool isInstantiated = false;
|
||||
static final MQTTHelper instance = MQTTHelper._privateConstructor();
|
||||
String lastMessage;
|
||||
|
||||
void onConnected(dynamic appContext) {
|
||||
void onConnected(AppContext appContext) {
|
||||
print('Connected !!!!!!!!!!!! ----------------------------------');
|
||||
HomieAppContext homieAppContext = appContext.getContext();
|
||||
|
||||
@ -26,7 +26,7 @@ class MQTTHelper {
|
||||
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}';
|
||||
appContext.setLastMessage('Received message:$payload from topic: ${c[0].topic}');
|
||||
|
||||
var topic = c[0].topic.split('/')[0];
|
||||
|
||||
@ -67,12 +67,6 @@ class MQTTHelper {
|
||||
print('Unsubscribed topic: $topic');
|
||||
}
|
||||
|
||||
String getLastMessage() {
|
||||
print("LAST MESSAAAGE");
|
||||
print(lastMessage);
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
Future<MqttServerClient> connect(dynamic appContext) async {
|
||||
HomieAppContext homieAppContext = appContext.getContext();
|
||||
|
||||
|
||||
@ -11,37 +11,57 @@ class DebugPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DebugPageState extends State<DebugPage> {
|
||||
List<String> lastMessages = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appContext = Provider.of<AppContext>(context);
|
||||
final AppContext appContext = Provider.of<AppContext>(context);
|
||||
String lastMessage = "test";
|
||||
|
||||
//lastMessage = MQTTHelper.instance.getLastMessage() == null ? "rien" : MQTTHelper.instance.getLastMessage();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Debug TODO"),
|
||||
title: Text("Debug"),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
"Last Message",
|
||||
),
|
||||
Text(
|
||||
MQTTHelper.instance.getLastMessage() == null ? "rien" : MQTTHelper.instance.getLastMessage(),
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
new Expanded(
|
||||
child: new ListView.separated
|
||||
(
|
||||
reverse: true,
|
||||
separatorBuilder: (context, index) {
|
||||
return Divider();
|
||||
},
|
||||
itemCount: appContext.getLastMQTTMessages()?.length,
|
||||
itemBuilder: (BuildContext ctxt, int Index) {
|
||||
if (appContext.getLastMQTTMessages().length > 0) {
|
||||
if (appContext.getLastMQTTMessages()[Index].toString().length > 350) {
|
||||
var textToShow = appContext.getLastMQTTMessages()[Index].toString().substring(0,350);
|
||||
return new Text("$textToShow ...");
|
||||
} else {
|
||||
return new Text(appContext.getLastMQTTMessages()[Index].toString());
|
||||
}
|
||||
}else {
|
||||
return new Text("rien");
|
||||
}
|
||||
}
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
/*floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => {},
|
||||
tooltip: 'Increment',
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),*/
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildBody(BuildContext context, int index) {
|
||||
return new Text(lastMessages[index]);
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,36 @@ class _HomePageState extends State<HomePage> {
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
drawer: Drawer(
|
||||
child: ListView(
|
||||
// Important: Remove any padding from the ListView.
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
const DrawerHeader(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
),
|
||||
child: Text('Drawer Header'),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Debug screen'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return DebugPage();
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
/*floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => {
|
||||
Navigator.push(
|
||||
context,
|
||||
@ -149,7 +178,7 @@ class _HomePageState extends State<HomePage> {
|
||||
},
|
||||
tooltip: 'Increment',
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),*/
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,7 @@ import 'Models/homieContext.dart';
|
||||
class AppContext with ChangeNotifier {
|
||||
HomieAppContext _homieContext;
|
||||
Client clientAPI;
|
||||
List<String> _lastMQTTMessages = [];
|
||||
|
||||
AppContext(this._homieContext);
|
||||
|
||||
@ -15,4 +16,15 @@ class AppContext with ChangeNotifier {
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
getLastMQTTMessages() => _lastMQTTMessages;
|
||||
setLastMessage(String lastMessage) async {
|
||||
_lastMQTTMessages.add(lastMessage);
|
||||
|
||||
if (_lastMQTTMessages.length > 10) {
|
||||
_lastMQTTMessages.removeAt(0);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
19
pubspec.lock
19
pubspec.lock
@ -63,7 +63,7 @@ packages:
|
||||
name: cupertino_icons
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.4"
|
||||
enum_to_string:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -142,6 +142,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.11"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -183,7 +190,7 @@ packages:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
version: "1.11.1"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -216,14 +223,14 @@ packages:
|
||||
name: sqflite
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0+4"
|
||||
version: "2.0.2"
|
||||
sqflite_common:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqflite_common
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1+1"
|
||||
version: "2.2.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -265,7 +272,7 @@ packages:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.3"
|
||||
version: "0.4.8"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -281,5 +288,5 @@ packages:
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
sdks:
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
dart: ">=2.15.0 <3.0.0"
|
||||
flutter: ">=1.16.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user