view_model_macro 0.0.6 copy "view_model_macro: ^0.0.6" to clipboard
view_model_macro: ^0.0.6 copied to clipboard

Experimental support for ViewModel classes in Dart using pckg:macros.

example/lib/main.dart

import 'package:example/calculator.dart';
import 'package:flutter/material.dart';
import 'package:view_model_macro/view_model_macro.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  final counter = Calculator();

  @override
  void dispose() {
    super.dispose();
  }

  void _onShowSnackBar(BuildContext context) {
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(content: Text('Show SnackBar from ActionNotifier')),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.add),
          onPressed: () => counter.add(),
        ),
        body: Builder(builder: (context) {
          return counter.showSnackBarStream.collectAsListener(
            onData: (_) => _onShowSnackBar(context),
            child: Center(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  counter.countStream.collectAsWidget(
                    (value) {
                      return Text('Count: $value');
                    },
                  ),
                ],
              ),
            ),
          );
        }),
      ),
    );
  }
}
3
likes
150
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

Experimental support for ViewModel classes in Dart using pckg:macros.

Repository (GitHub)
View/report issues

Topics

#macros #view-model

Documentation

API reference

License

MIT (license)

Dependencies

flutter, macros, meta, rxdart

More

Packages that depend on view_model_macro