flutter_command 0.9.0 copy "flutter_command: ^0.9.0" to clipboard
flutter_command: ^0.9.0 copied to clipboard

outdated

flutter_command is a way to manage your state based on `ValueListenable` and the `Command` design pattern. Sounds scary uh? Ok lets try it a different way. A `Command` is an object that wraps a functi [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

import 'homepage.dart';
import 'weather_viewmodel.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() {
    return MyAppState();
  }
}

class MyAppState extends State<MyApp> {
  WeatherViewModel viewModel;

  @override
  void initState() {
    viewModel = WeatherViewModel();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return TheViewModel(
      theModel: viewModel,
      child: MaterialApp(title: 'Flutter Demo', home: HomePage()),
    );
  }
}

// InheritedWidgets allow you to propagate values down the widgettree.
// it can then be accessed by just writing  TheViewModel.of(context)
class TheViewModel extends InheritedWidget {
  final WeatherViewModel theModel;

  const TheViewModel({Key key, @required this.theModel, @required Widget child})
      : assert(theModel != null),
        assert(child != null),
        super(key: key, child: child);

  static WeatherViewModel of(BuildContext context) =>
      context.dependOnInheritedWidgetOfExactType<TheViewModel>().theModel;

  @override
  bool updateShouldNotify(TheViewModel oldWidget) =>
      theModel != oldWidget.theModel;
}
69
likes
0
pub points
83%
popularity

Publisher

unverified uploader

flutter_command is a way to manage your state based on `ValueListenable` and the `Command` design pattern. Sounds scary uh? Ok lets try it a different way. A `Command` is an object that wraps a function that can be executed by calling the command, therefore decoupling your UI from the wrapped function.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, functional_listener, quiver_hashcode

More

Packages that depend on flutter_command