flutter_compute_tree 1.0.0+9 flutter_compute_tree: ^1.0.0+9 copied to clipboard
Easy way to bind your data to Flutter widgets
import 'package:flutter/material.dart';
import 'package:flutter_compute_tree/flutter_compute_tree.dart';
import 'package:flutter_compute_tree_example/ref_action.dart';
import 'package:flutter_compute_tree_example/trigger_handler.dart';
import 'async_handler_trigger.dart';
import 'invoke.dart';
import 'invoke_async.dart';
import 'memo.dart';
import 'ref.dart';
void main() {
const apps = [
RefApp(),
InvokeApp(),
InvokeAsyncApp(),
AsyncHandlerTriggerApp(),
MemoApp(),
TriggerHandlerApp(),
RefActionApp(),
];
runApp(const App(apps: apps));
}
class App extends StatelessWidget {
final List<Widget> apps;
const App({super.key, required this.apps});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: NodeBuilder((ctNode) {
final selectedAppIndex = ref(() => 0);
final app = apps[selectedAppIndex.value];
return Scaffold(
appBar: AppBar(
title: Text(app.toStringShort()),
),
body: Center(
child: PlatformMenuBar(
menus: [
const PlatformMenu(
label: 'Context tree',
menus: [],
),
PlatformMenu(
label: 'Apps',
menus: [
PlatformMenuItemGroup(
members: [
for (int i = 0; i < apps.length; i++)
PlatformMenuItem(
label:
apps[i].toStringShort().replaceAll('App', ''),
onSelected: () => selectedAppIndex.value = i,
)
],
)
],
)
],
child: app,
),
),
);
}),
);
}
}