#[rid::store]
#[rid::structs(Todo)]
pub struct Store {
todos: Vec<Todo>,
}
impl rid::RidStore<Msg> for Store {
fn create() -> Self {
Self { todos: vec![Todo { title: "Try Rid".to_string() }] }
}
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));
}
}
}
}
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}'),
));
}
}
Interface from Flutter to Rust without writing complex and error prone FFI boilerplate.
Author your application logic in Rust to benefit from its security and speed.
Benefit from Flutter's hot reload feature while creating the UI of your application.