flutter_compute_tree 1.0.0+18 copy "flutter_compute_tree: ^1.0.0+18" to clipboard
flutter_compute_tree: ^1.0.0+18 copied to clipboard

Easy way to bind your data to Flutter widgets

example/lib/main.dart

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 '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(),
    StreamSubscriptionApp(),
  ];

  runApp(const App(apps: apps));
}

class App extends StatelessWidget {
  final List<Widget> apps;

  const App({super.key, required this.apps});

  Iterable<PlatformMenuItem> menuItems(Trigger<int> selectApp) sync* {
    for (int i = 0; i < apps.length; i++) {
      final app = apps[i];
      final label = app.toStringShort().replaceAll('App', '');

      yield PlatformMenuItem(
        label: label,
        onSelected: () => selectApp(i),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(useMaterial3: true),
      home: CTBuilder((n) {
        final selectedAppIndex = n.ref(() => 0);
        final selectApp = n.trigger<int>();
        selectApp.handler((index) => selectedAppIndex.value = index, 0);

        final app = apps[selectedAppIndex.value];

        return Scaffold(
          appBar: AppBar(
            title: Text(app.toStringShort()),
          ),
          body: Center(
            child: PlatformMenuBar(
              menus: [
                const PlatformMenu(
                  label: 'Flutter Context Tree Examples',
                  menus: [],
                ),
                PlatformMenu(
                  label: 'Apps',
                  menus: [
                    PlatformMenuItemGroup(
                      members: [
                        ...menuItems(selectApp),
                      ],
                    )
                  ],
                )
              ],
              child: app,
            ),
          ),
        );
      }),
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Easy way to bind your data to Flutter widgets

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, matches

More

Packages that depend on flutter_compute_tree