Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
MQTT-Project/MQTT Project-Software.py.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
988 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_mqtt/mqtt_client.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: MQTTScreen(), | |
); | |
} | |
} | |
class MQTTScreen extends StatefulWidget { | |
@override | |
_MQTTScreenState createState() => _MQTTScreenState(); | |
} | |
class _MQTTScreenState extends State<MQTTScreen> { | |
MQTTClient mqttClient = MQTTClient(); | |
@override | |
void initState() { | |
super.initState(); | |
mqttClient.prepareClient(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('MQTT Mobile App'), | |
), | |
body: Center( | |
child: ElevatedButton( | |
onPressed: () { | |
mqttClient.publishMessage('Topic', 'Message'); | |
}, | |
child: Text('Publish Message'), | |
), | |
), | |
); | |
} | |
} |