Skip to content
Permalink
5dc43247ae
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
47 lines (41 sloc) 988 Bytes
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'),
),
),
);
}
}