roslib 0.0.3 copy "roslib: ^0.0.3" to clipboard
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.

example/main.dart

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();
                    },
                  ),
                ],
              ),
            );
          }),
    );
  }
}
9
likes
40
pub points
37%
popularity

Publisher

unverified uploader

Interface with a ROS node over websockets with rosbridge, heavily influenced by roslibjs and follows the same structure.

Repository (GitHub)
View/report issues

License

GPL-3.0 (license)

Dependencies

flutter, web_socket_channel

More

Packages that depend on roslib