flutter_compute_tree 1.0.0+20 flutter_compute_tree: ^1.0.0+20 copied to clipboard
Flutter data binding framework
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/stream_subscription.dart';
import 'package:flutter_compute_tree_example/trigger_handler.dart';
import 'package:flutter_compute_tree_example/value_listenable_subscription.dart';
import 'async_handler_trigger.dart';
import 'invoke.dart';
import 'invoke_async.dart';
import 'memo.dart';
import 'ref.dart';
import 'src/app.dart';
const apps = <App>[
RefApp(),
InvokeApp(),
InvokeAsyncApp(),
AsyncHandlerTriggerApp(),
MemoApp(),
TriggerHandlerApp(),
RefActionApp(),
StreamSubscriptionApp(),
ValueListenableSubscriptionApp(),
];
void main() {
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
static Key appKey = GlobalKey();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(useMaterial3: true),
home: CTBuilder((n) {
final mq = MediaQuery.of(n.context);
final selectedIndex = n.ref(() => 0);
final select = selectedIndex.action((value, int arg) => arg);
final selectedApp = n.invoke(
() => apps[selectedIndex.value],
selectedIndex.value,
);
final navRail = NavigationRail(
extended: true,
minExtendedWidth: 300,
backgroundColor: Colors.transparent,
destinations: [
for (final app in apps)
NavigationRailDestination(
icon: app == selectedApp
? const Icon(Icons.play_arrow)
: const SizedBox(),
label: Text(app.name),
)
],
selectedIndex: selectedIndex.value,
onDestinationSelected: select,
);
final drawer = n.invoke(
() => mq.size.width < 700 ? Drawer(child: navRail) : null,
mq.size.width < 700,
);
final child = KeyedSubtree(
key: appKey,
child: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: selectedApp,
),
),
);
return Scaffold(
appBar: AppBar(title: Text(selectedApp.name)),
drawer: drawer,
body: mq.size.width > 700
? Row(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Card(
child: SingleChildScrollView(
child: IntrinsicHeight(child: navRail),
),
),
),
Expanded(child: child),
],
)
: child,
);
}),
);
}
}