Introduction

Rid makes it easy to integrate Rust application logic with your Flutter UI.

Quick Start

Please have a look at the below snippets to get an idea of how Rid helps you integrate your Flutter/Dart UI with your application logic implemented in Rust. Then continue by reading about the Rid Application Architecture →

Rust

#[rid::store]
#[rid::structs(Todo)]
pub struct Store {
    todos: Vec<Todo>,
}

impl rid::RidStore<Msg> for Store {
     fn create() -> Self {
        let todos = vec![Todo { title: "Learn Rust".to_string() }]; 
        Self { todos }
    }
    
    fn update(&mut self, req_id: u64, msg: Msg) {
        match msg {
            Msg::AddTodo(title) => {
                self.todos.push(Todo { title });
                rid::post(Reply::AddedTodo(req_id));
            }
        }
    }
}

#[rid::message(Reply)]
pub enum Msg {
    AddTodo(String),
}

#[rid::reply]
pub enum Reply {
    AddedTodo(u64),
}

#[rid::model]
pub struct Todo {
  title: String
}

Dart

final store = Store.instance;

await store.msgAddTodo('Learn Rid');

for (final todo in store.todos) {
    print("${todo.title}");
}

Flutter

void main() {
  final store = Store.instance;
  runApp(TodoApp(model));
}
// [ .. ]
class TodosView extends StatelessWidget {
  final Store store;
  TodosView(this.store, {Key? key}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    final todos = store.todos;
    return Center(
      child: ListView.builder(
      itemCount: todos.length,
      itemBuilder: (_, index) => Text('${todos[index].title}'),
    ));
  }
}

👉 If you like to look at more detailed code samples head on over to the rid-examples repository.

Get Involved

Please sponsor Rid development so it can evolve and stay maintained.

Contributing

Find out how to contribute to Rid. Contributing →