flutter_rosutils 0.0.2+1

ROS Utils for Dart #

A simple library for syncing using ROS in flutter applications using roslib.

Work in progress

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_rosutils/flutter_rosutils.dart';
import 'package:provider/provider.dart';

class CommandMessage extends RosMessage {
  int command;
  static const INITIALIZE_ALL = 0;
  static const SHUTDOWN = 10;
  static const START_GAME = 20;

  CommandMessage._(this.command);
  factory CommandMessage(dynamic message) {
    return CommandMessage._(message['msg']['command']);
  }

  CommandMessage.initialize() {
    command = INITIALIZE_ALL;
  }

  CommandMessage.shutdown() {
    command = SHUTDOWN;
  }

  CommandMessage.startGame() {
    command = START_GAME;
  }

  @override
  dynamic get serializedMessage => {'command': command};

  String get message {
    switch (command) {
      case INITIALIZE_ALL:
        return 'initialize';
      case START_GAME:
        return 'start game';
      case SHUTDOWN:
        return 'shutdown';
      default:
        return 'none';
    }
  }
}

class ExampleBloc {
  Ros _ros;
  RosMessageTopic<CommandMessage> messageTopic;

  ExampleBloc() {
    _ros = Ros(url: 'ws://127.0.0.1:9090');
    messageTopic = RosMessageTopic<CommandMessage>(ros: _ros, name: 'command', type: 'custom_msgs/CommandMessage');
  }

  void connect() {
    _ros.connect();
    messageTopic.connect((message) => CommandMessage(message));
  }

  void sendInitMessage() {
    messageTopic.value = CommandMessage.initialize();
  }
}

void main() {
  final bloc = ExampleBloc();
  bloc.connect();
  runApp(
    Provider<ExampleBloc>.value(
      value: bloc,
      child: StreamProvider<CommandMessage>.value(
        value: bloc.messageTopic.stream,
        child: MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  MyApp();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Bloc Demo'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;
  MyHomePage({this.title, key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final appState = Provider.of<ExampleBloc>(context);
    final currentMessage = Provider.of<CommandMessage>(context).message;
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Current Message: $currentMessage',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: appState.sendInitMessage,
        tooltip: 'Send Init',
        child: Icon(Icons.play_arrow),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_rosutils: ^0.0.2+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_rosutils/flutter_rosutils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
58
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [flutter_rosutils] that is in a package requiring null.

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:flutter_rosutils/flutter_rosutils.dartpackage:roslib/roslib.dartpackage:roslib/actionlib/actionlib.dartpackage:roslib/actionlib/action_client.dartpackage:roslib/core/core.dartpackage:roslib/core/param.dartpackage:roslib/core/service.dartpackage:roslib/core/ros.dartpackage:web_socket_channel/io.dartdart:io

Health suggestions

Format lib/src/ros_utils.dart.

Run flutter format to format lib/src/ros_utils.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
roslib ^0.0.3 0.0.3
rxdart ^0.23.1 0.23.1 0.24.1
Transitive dependencies
async 2.4.2
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.5
meta 1.1.8 1.2.1
sky_engine 0.0.99
stream_channel 2.0.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
web_socket_channel 1.1.0
Dev dependencies
flutter_test