Flutter App Development

Flutter app development: Connecting Flutter apps with ROS

Flutter App Development: Connecting Flutter Apps with ROS

Robot Operating System (ROS) is a widely used open-source framework for building robotic applications, offering navigation, manipulation, and sensor integration tools within Flutter apps.

Integrating ROS with mobile platforms like Flutter enables real-time monitoring, control, and data visualization, enhancing the flexibility of robotics in applications such as industrial automation and research.

However, existing Flutter packages for ROS face challenges, including outdated SDK compatibility, incomplete features, poor documentation, and limited maintenance, hindering their reliability and scalability.

Addressing these issues through modern approaches like WebSocket-based communication can unlock the full potential of ROS in Flutter apps.

Understanding ROS 

ROS is an open-source framework that acts as a middleware for complex robotics systems development. It’s not an operating system in the traditional sense, but rather a set of tools, libraries, and utilities for robotics software development. 

Robotic systems consist of different parts, and ROS acts like the glue between them. ROS provides the infrastructure for messaging between components, hardware abstraction, and real-time data sharing.  

Since ROS is open source, it relies on community-driven libraries and packages. There are currently two versions: ROS and ROS 2. The original system was released in 2007 and is widely used, while ROS 2 is a modernized version with better real-time support and security features.  

Available Flutter app packages for ROS

Flutter is a leading platform for cross-platform app development released by Google. While it is mostly known for mobile app development, the SDK also offers features for robotics and embedded software development.  

Here are the available Flutter ROS packages:

1. Dartros

The Dartros package is a Dart-based ROS client library inspired by C++ and Node.js implementations. It enables ROS operations, such as connecting to a ROS master, publishing/subscribing to topics, and generating custom message types for inter-node communication.   

Features of Dartros

  • Publish/Subscribe (TCP): Reliable topic communication with standard messages (std_msgs, sensor_msgs). 
  • Services: Handles client-server interactions between nodes. 
  • Message Generation: Supports custom ROS message creation via the gendart package. 
  • ROS Master Connection: Compatible with both local and remote masters. 

Advantages of Dartros

  • Simplifies ROS integration in Dart/Flutter apps. 
  • Pre-published message libraries for easy dependency management. 
  • Supports TCP-based communication for reliability. 

Limitations of Dartros

  • SDK Compatibility: Limited to Dart SDK versions 2.12.0–3.4.0, incompatible with the latest versions.  
  • Documentation Gaps: Minimal API docs requiring reliance on examples.  
  • Platform and Maintenance: Lacks platform support testing and is no longer actively maintained.  
  • Setup Complexity: Custom message generation depends on the external setup of the Gendart package. 

2. Viam Flutter SDK 

Viam is a software platform for building robots and smart devices. The Viam Flutter SDK enables you to create custom mobile applications that interact with the robot or smart device. It does that by allowing mobile or desktop UIs to interact with ROS-powered robots. Viam supports both ROS and Flutter ROS 2 integration. 

Features of Viam Flutter SDK

  • gRPC over WebRTC communication: Enables low-latency, real-time connections between Flutter apps and Viam-enabled robots across networks. 
  • Cross-platform compatibility: Supports Flutter apps on iOS, Android, desktop, and web to interface with robots. 
  •  Device control APIs: Control robotic hardware (e.g., send movement commands, adjust parameters) via Flutter UI. 
  • Authentication and session management: Secure communication with devices registered to your Viam account. 

Advantages of Viam Flutter SDK

  • Rapid app development: Enables fast prototyping and deployment of robot UIs without writing native code for each platform. 
  • Truly mobile robot control: Enables you to build on-the-go control panels and monitoring tools for robots directly from your smartphone or tablet. 
  • Real-time bi-directional communication: Suitable for live robotics use cases like remote inspection, robotics demos, or mobile dashboards. 
  • Component abstraction: Works seamlessly regardless of hardware type, thanks to Viam’s component-based design. 

Limitations of Viam Flutter SDK

  • Still maturing: As of 2025, the SDK is functional but evolving; some components or configurations may lack complete documentation. 
  • Viam platform dependency: The SDK is compatible only with robots registered on Viam’s cloud, not with generic ROS or standalone robot solutions. 
  • Limited offline capabilities: Primarily designed for cloud-connected robots; less suited for fully offline or air-gapped systems. 
  • ROS integration is indirect: While Viam can interface with ROS, the Flutter SDK does not talk to ROS directly; rather, it routes through the Viam backend

Implementation of Dartros

In this guide, we’ll be explaining how to connect Flutter apps with ROS using dartros.

1. Add Dependency
Include Dartros in your pubspec.yaml file. 

Dependencies:
  dartros: ^0.2.1 

Code snippet


Flutter Apps Packages for ROS

Explanation

  1. Connect to ROS Master
    Establish a WebSocket connection to the ROS master using its IP address (e.g., ws://<ROS_MASTER_IP>:9090). 
  2. Create a ROS Node
    Initialize a ROS node instance to manage communication with the ROS master. 
  3. Define Topics
    Specify the topic names and their message types (e.g., /chatter with std_msgs/String). 
  4. Publish Messages
    Use a Publisher instance to send messages to a specified topic. 
  5. Subscribe to Messages
    Use a Subscriber instance to listen for messages on a topic and handle them via a callback function.

2. Ros Nodes

Overview of Ros Nodes

  • ros_nodes is a Dart package designed for direct ROS node implementation. 
  • It supports creating ROS nodes in Dart and enabling topic publishing and subscription. 

Features of Ros Nodes

  • Direct node creation and connection to the ROS master. 
  • Supports publishing and subscribing to topics. 

Limitations of Ros Nodes

  • Limited support for complex message types and services. 
  • No native WebSocket or ROSBridge integration, restricting its usage in environments where direct TCP communication is not feasible. 
  • Less mature compared to other ROS libraries, with limited community support. 
  • No Documentation is available, which will eventually increase development time and difficulty for the developer 
  • Works only with ancient Flutter SDK versions (up to 3.7.1), making it incompatible with our application  

Implementation of Ros Nodes

The following code is used to connect to ROS with your Flutter apps

After the installation of ROS on your Linux, just follow these steps for the same execution 

Step 1: Get the IP address of your VM (Virtual Machine) using ifconfig 

Step 2: Add dependency in pubspec.yaml  

dependencies:
ros_nodes:
  git:
    url: https://github.com/Sashiri/ros_nodes.git 

Step 3: In the RosConfig function, update your (Local Machine) IP address   

Step 4: Run the app and enter the IP address of the VM in the textbox. A topic will be created 

Code snippet

Flutter Apps Packages for ROS3. roslib

Overview of roslib

roslib is a Dart library that communicates with ROS nodes over WebSockets using the rosbridge protocol. Inspired by roslibjs, it implements a subset of features required for ROS communication, including topics, services, and parameters.

However, it is an incomplete library, lacking advanced features and compatibility with modern Dart versions. 

Features of roslib

Core Components: 

  • ROS Connection: Manages WebSocket communication with ROS. 
  • Topic Object: Supports subscribing, unsubscribing, publishing, advertising, and unadvertising topics. 
  • Service Object: Facilitates service calls, advertisements, and non-advertisements. 
  • Request Object: Provides structured naming and typing for ROS requests. 
  • Param Object: Enables getting, setting, and deleting ROS parameters. 

Missing features of roslib

  • Actionlib: Components like ActionClient, ActionListener, Goal, and SimpleActionServer are not implemented. 
  • TFClient: No support for TF data from tf2_web_republisher. 
  • URDF Support: Lacks functionality for handling URDF elements like models, joints, and materials. 
  • TCP Connections: No support for ROS communication over TCP. 

Limitations of roslib

  • Incomplete Implementation: Several critical features, such as Actionlib and TFClient, remain unimplemented.  
  • Dart SDK Incompatibility: Supports Dart <3.0.0, making it incompatible with modern Dart SDK versions (e.g., 3.6.0) and null safety.  
  • Static Analysis Issues: Fails due to outdated dependencies and unresolved constraints.  
  • Platform Support: Unable to detect supported platforms due to dependency resolution issues. 

roslib is suitable for basic ROS-WebSocket communication but requires further development to be viable for modern applications. 

Implementation of roslib

Add Dependency
Include Dartros in your pubspec.yaml file. 

Dependencies:
  Flutter:
    sdk: flutter
  roslib: ^0.2.0

Code snippet

Flutter Apps Packages for ROS

Explanation

  • Install ROS: Ensure ROS is installed and run roscore in a terminal.  
  • Publish Test Message: Use rostopic pub to send a message to the /chatter topic.  
  • Set Up Flutter Project: Create a new Flutter project and add roslib as a dependency.  
  • Write Code: Replace lib/main.dart with the provided code.  
  • Run Flutter App: Connect to the ROS WebSocket and run the app.  
  • Test Communication: The app should display the message received from ROS, and you can check the /chatter topic using rostopic echo.  
  • Expected Output: The Flutter apps will show the published message, and ROS should display the same message

Comparative analysis

comparative analysis of features

The solution: WebSocket and Rosbridge

WebSocket is a communication protocol that enables full-duplex interaction between clients and servers, making it ideal for real-time applications.

Rosbridge, a middleware layer for ROS, provides a JSON API that allows non-ROS systems to interact with ROS nodes seamlessly. Together, they offer a streamlined solution for connecting ROS to modern mobile applications. 

Advantages of WebSocket and Rosbridge

1. Modern Dart/Flutter apps compatibility

Unlike traditional ROS integration methods, WebSocket and rosbridge are compatible with contemporary Dart and Flutter frameworks. This eliminates the need to rely on outdated or unsupported libraries, ensuring smooth development and deployment. 

2. Scalability and flexibility

This approach supports many robotics applications, from small-scale automation to complex systems, without compromising performance. The flexible JSON-based communication makes it easy to adapt to various use cases and system requirements. 

3. Eliminates outdated dependencies

By leveraging WebSocket and rosbridge, developers can bypass older, deprecated packages and instead use a modern, lightweight solution. This results in cleaner, more maintainable code and a future-proof application architecture. 

Step-by-step guide to using WebSocket and Rosbridge in Flutter apps

1. Setting up rosbridge

  • Install and configure rosbridge_suite on your ROS system. 
  • Launch the WebSocket server using roslaunch rosbridge_server rosbridge_websocket.launch.
    This allows external applications, including Flutter, to communicate with ROS nodes via WebSocket. 

2. Establishing WebSocket communication

  • Use the web_socket_channel package in Flutter app development to initiate a WebSocket connection. 
  • Connect to the ws://<ROS-IP>:9090 endpoint and handle errors and disconnections to ensure stability. 

3. Publishing and subscribing to topics

  • Send a JSON message to advertise and publish to ROS topics. 
  • Similarly, subscribe to topics by sending a JSON subscription message.
  • This enables seamless data exchange between your Flutter app development and ROS. 

4. Handling custom messages

  • Define custom ROS message types in your ROS environment and ensure your Flutter app’s JSON structure matches these types. 
  • Use appropriate topic names and data formats to avoid communication errors. 

5. Testing communication

  • Use ROS tools like rostopic echo to monitor message flow. 
  • Verify publishing with rostopic pub to ensure correct message formats and topic handling. 

Conclusion

Integrating Flutter apps with ROS using WebSocket and rosbridge offers a modern, flexible, and scalable approach to building robotics applications.

Developers can achieve real-time data exchange and robust functionality by bypassing outdated dependencies and leveraging direct WebSocket communication.

This method empowers mobile applications to interface seamlessly with ROS, unlocking new possibilities in robotics and automation while maintaining compatibility with modern Flutter standards. 

If you need further help with Flutter app development, you can contact us at [email protected]. We will schedule a free consultation session to explore how Xavor can assist you. 

Scroll to Top