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

An all-in-one package for state management, reactive objects, animations, effects, timed widgets etc.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:frideos/frideos.dart';

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

class AppState extends AppStateModel {
  factory AppState() => _singletonAppState;

  AppState._internal();

  static final AppState _singletonAppState = AppState._internal();

  // STREAM
  final counter = StreamedValue<int>();

  void incrementCounter() {
    counter.value++;
  }

  @override
  void init() {
    counter.value = 0;
  }

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  AppState appState;

  @override
  void initState() {
    super.initState();
    appState = AppState();
  }

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

  @override
  Widget build(BuildContext context) {
    return AppStateProvider<AppState>(
      appState: appState,
      child: MaterialApp(
        title: 'Counter',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appState = AppStateProvider.of<AppState>(context);

    return Scaffold(
      appBar: AppBar(
        title: const Text('Main page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('Counter:'),
                Container(width: 30),
                ValueBuilder<int>(
                  streamed: appState.counter,
                  builder: (context, snapshot) => Text('${snapshot.data}'),
                  noDataChild: const Text('null'),
                ),
              ],
            ),
            Container(height: 30),
            RaisedButton(
                child: const Text('Second page'),
                onPressed: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) => SecondPage()));
                }),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: appState.incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appState = AppStateProvider.of<AppState>(context);

    return Scaffold(
      appBar: AppBar(
        title: const Text('Other page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                const Text('Counter:'),
                Container(width: 30),
                ValueBuilder<int>(
                  streamed: appState.counter,
                  builder: (context, snapshot) => Text('${snapshot.data}'),
                  noDataChild: const Text('null'),
                ),
              ],
            ),
            Container(height: 30),
            RaisedButton(
                child: const Text('Other page'),
                onPressed: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) => SecondPage()));
                }),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: appState.incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
41
likes
40
pub points
71%
popularity

Publisher

unverified uploader

An all-in-one package for state management, reactive objects, animations, effects, timed widgets etc.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (LICENSE)

Dependencies

flutter, rxdart

More

Packages that depend on frideos