Create a mobile app

You can use Viam’s Flutter SDK to create a custom mobile application to interact with your devices. The Flutter SDK includes:

  • Implementation of the standard component and service APIs to control your hardware and software
  • Widgets to ease the development process
  • Authentication tools so users can log in securely

Install the Flutter SDK

Run the following command in your terminal to install the Viam Flutter SDK:

flutter pub add viam_sdk

Connect to your machine

You can find sample connection code on each machine’s CONNECT tab in the Viam app. Select Flutter to display a code snippet with connection code as well as some calls to the APIs of the resources you’ve configured on your machine.

You can use the toggle to include the machine API key and API key ID, though we strongly recommend storing your API keys in environment variables to reduce the risk of accidentally sharing your API key and granting access to your machines.

If your code will connect to multiple machines or use Platform APIs you can create an API key with broader access.

Write your app

Refer to the Viam Flutter SDK documentation for available methods and widgets.

Example usage

The following code, part of Drive a rover in a square in 2 minutes, shows how you could move a robotic rover base in a square using the base API’s moveStraight and spin methods:

import 'package:flutter/material.dart';
import 'package:viam_sdk/viam_sdk.dart';
import 'package:viam_sdk/widgets.dart';

class BaseScreen extends StatelessWidget {
  final Base base;

  const BaseScreen(this.base, {super.key});

  Future<void> moveSquare() async {
    for (var i=0; i<4; i++) {
      await base.moveStraight(500, 500);
      await base.spin(90, 100);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(base.name)),
      body: Center(
        child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
              onPressed: moveSquare,
              child: const Text('Move Base in Square'),
            ),
        ]))
        ,);}}

See the guide for full code and instructions to get started by building a simple app to control a rented Viam rover:

For a more in-depth guide with more screens, see the following guide:

Test your app

You can use the mobile app simulator on your development computer to test your app. The connection code will establish communication with your machine over LAN or WAN.

Set up user authentication

Viam uses FusionAuth for authentication and authorization.

Use the Viam CLI auth-app command to register your application with FusionAuth so that you or your users can log into your app with the same credentials they use to log into the Viam app.

For support building apps with custom login flows, contact us.

Next steps

To publish your app to the app stores when you’re done testing and adding authentication, see Flutter’s articles: