Flutter

Experience the amazing productivity & type safety from effortlessly calling .NET APIs from Flutter and Dart Apps

App screenshot

Flutter iOS and Android Apps

Rapidly develop beautiful native cross-platform iOS and Android Apps with Flutter's beautiful widgets calling ServiceStack's HTTP and gRPC end-to-end typed .NET API integrations Learn more

flutter android api

Flutter Todo App with .NET API, from Scratch in Minutes

This video starts from scratch, walking through installing Flutter SDK, before adding a new native Flutter App to a new .NET Blazor Server project - giving our existing TODO Blazor Web App new native iOS & Android native UIs

Next, we'll demonstrate the iterative development workflow of making changes to backend .NET APIs that's easily kept in-sync with our clients Dart DTOs from within Android Studio or command-line

flutter android api

Use Flutter to build a Bookings App Fast

In this video, we'll show how we can rapidly develop a new Flutter Android Bookings App added to a new blazor .NET Project using x mix flutter

Next, we'll dive into the development process, where we'll demonstrate the productivity of calling typed .NET APIs using typed Dart DTOs for end-to-end typed integrations that can be effortlessly updated from within Android Studio

Dart and Flutter gRPC

ServiceStack gRPC is an alternative approach for enabling high-performance end-to-end typed APIs using gRPC generated clients that benefits from ServiceStack's simplified gRPC tooling and reuse of existing HTTP APIs Learn more

grpc flutter android

Fastest way to a working gRPC Server and Flutter solution

In this video we'll walk through configuring Flutter and gRPC .NET Services with the flutter-grpc mix template to add a new Flutter application using your locally installed Flutter SDK to an existing ServiceStack grpc project that has been configured to support gRPC services

dart grpc

Enabling Dart gRPC support to ServiceStack .NET Apps

In this video we walk through how to enable gRPC endpoints for your existing ServiceStack services and how the x dotnet tool greatly simplifies the development workflow of maintaining in-sync client integrations in a simple and consistent way across all gRPC languages

Getting Started

Create a Flutter App with a .NET API backend

In this example we'll walk through creating a new Flutter Mobile App with a .NET API backend and demonstrate the development workflow of calling new .NET APIs with typed client APIs from Flutter

Pre-requisites

Ensure you have the Flutter SDK and the x dotnet tool installed:

Both Flutter and .NET have great CLI tooling where you can get a great development experience using a text editor like VS Code with its great multi-terminal support, or if preferred, full-featured IDEs like Android Studio and JetBrains Rider for even richer tooling.

1. Create your .NET Project

Start with your preferred project, or create an empty Project with your preferred project name:

That can be run immediately in the Host project with dotnet watch for a live reload dev UX:

2. Add a new Flutter App to your project

Then from a new Terminal in your Solution folder (e.g. MyApp), add a new Flutter App with:

This will run flutter create to add a new Flutter App to your solution that should look like:

It also adds the servicestack client library package that's pre-configured to call the default Hello API in new ServiceStack projects which we can test by running fluter from myapp_flutter:

We recommend choosing [1] to run the Flutter App as a Windows Desktop App for the best dev UX on Windows, which after a few moments should open the Hello App in a Desktop App:

3. Create your .NET API

Lets create a new API to preview the typical dev workflow of calling new .NET APIs from Flutter. First we'll want to define our API's Service Contract with the Request and Response DTOs the API will accept and return in:

MyApp.ServiceModel/SearchFiles.cs
using ServiceStack;
using System.Collections.Generic;

namespace MyApp.ServiceModel;

public class SearchFiles : IReturn<SearchFilesResponse>
{
   public string Pattern { get; set; }
}

public class SearchFilesResponse
{
   public List<string> Results { get; set; }
}

Then add its Implementation that scans the .NET App's folder for files and returns the results:

MyApp.ServiceInterface/SearchFilesService.cs
using ServiceStack;
using MyApp.ServiceModel;

namespace MyApp.ServiceInterface;

public class SearchFilesServices : Service
{
   public object Any(SearchFiles request)
   {
       var files = VirtualFiles.GetAllMatchingFiles(request.Pattern ?? "*");
       return new SearchFilesResponse {
           Results = files.Map(x => x.VirtualPath)
       };
   }
}

dotnet watch should automatically detect the changes and reload the App to take effect.

3. Update Flutter App

Then to update our clients Dart DTOs we just need to run x dart from the Flutter project:

Which can now be used in our App, by replacing the callService() and build() methods with:

void callService() async {
 var response = await client.get(SearchFiles(pattern: myController.text));
 setState(() {
   result = response.results!.join('\n');
 });
}

@override
Widget build(BuildContext context) {
 return Scaffold(
   appBar: AppBar(title: Text(widget.title),),
   body: Center(
     child: Column(
       mainAxisAlignment: MainAxisAlignment.center,
       children: <Widget>[
         Container(
           padding: const EdgeInsets.only(top: 20),
           margin: const EdgeInsets.only(left: 100.0, right: 100.0),
           child: Column(
             children: [
               const Text(
                 'Search Files',
                 style:
                     TextStyle(fontWeight: FontWeight.bold, fontSize: 24.0),
               ),
               TextField(
                 decoration: const InputDecoration(
                   border: OutlineInputBorder(),
                   hintText: '*',
                 ),
                 controller: myController,
               )
             ],
           ),
         ),
         Padding(
           padding: const EdgeInsets.all(8.0),
           child: Text(
             result,
             style: const TextStyle(fontSize: 18),
           ),
         ),
       ],
     ),
   ),
 );
}

Which after a restart should now call our new SearchFiles API returning .NET App files that match the specified pattern:

We hope this was a good waltkthrough to showcase the simplified end-to-end typed dev model for working with ServiceStack's APIs, be sure to check out the Flutter videos for more in-depth explanations or head over to our Support Channels if you have any issues or questions.

Adobe
NBC Universal
Progress Software
EA
Honeywell
nVidia