roslib 0.0.3 roslib: ^0.0.3 copied to clipboard
Interface with a ROS node over websockets with rosbridge, heavily influenced by roslibjs and follows the same structure.
import 'package:flutter/material.dart';
import 'package:roslib/roslib.dart';
void main() {
runApp(ExampleApp());
}
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Roslib Example',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Ros ros = Ros(url: 'ws://10.0.2.2:9090');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Roslib Example'),
),
body: StreamBuilder<Object>(
stream: ros.statusStream,
builder: (context, snapshot) {
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ActionChip(
label: Text(snapshot.data == Status.CONNECTED
? 'DISCONNECT'
: 'CONNECT'),
backgroundColor: snapshot.data == Status.CONNECTED ? Colors.green[300] : Colors.grey[300],
onPressed: () {
if (snapshot.data == Status.CONNECTED)
ros.close();
else
ros.connect();
},
),
],
),
);
}),
);
}
}