rx_widgets 1.0.1 copy "rx_widgets: ^1.0.1" to clipboard
rx_widgets: ^1.0.1 copied to clipboard

outdated

Stream based Widgets and Widget convenience classes to support an reactive programming style

example/lib/main.dart

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

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

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

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
 
  @override
  MyAppState createState() {
    return new MyAppState();
  }
}


class MyAppState extends State<MyApp> {

  WeatherViewModel viewModelData;
  
  @override 
  void initState() {

      viewModelData = new WeatherViewModel();
      super.initState();
    }

  @override
  Widget build(BuildContext context) {
    // Place the Inherited Widget at the very base of the Widget tree        
    return new TheViewModel( 
                  theModel:  viewModelData,
                  child: 
                  new MaterialApp(
                    title: 'Flutter Demo',
                    home: new 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.inheritFromWidgetOfExactType(TheViewModel)as TheViewModel).theModel;                  


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

Publisher

unverified uploader

Stream based Widgets and Widget convenience classes to support an reactive programming style

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, rx_command

More

Packages that depend on rx_widgets