osam_flutter 2.1.3 copy "osam_flutter: ^2.1.3" to clipboard
osam_flutter: ^2.1.3 copied to clipboard

discontinued
outdated

Navigation and UI elements which fits with Osam library

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:osam_flutter/osam_flutter.dart';

void main() async {
  final core = Core();
  runApp(MaterialApp(
    home: App(core),
  ));
}

class App extends StatefulWidget {
  final Core core;

  const App(this.core);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            widget.core.update((state) {
              state.num = 0;
              state.news.clear();
            });
            Future.delayed(Duration.zero, () {
              widget.core.update((state) {
                state.num = 1;
                state.news.add(News(state.num));
              });
            });
          });
        },
      ),
      appBar: AppBar(
        title: OsamBuilder<int>(
          stream: widget.core.propertyStream((state) => state.num),
          builder: (ctx, value) {
            return GestureDetector(
              child: Text(value.toString()),
              onTap: () => widget.core.update((state) {
                state.update((state) {
                  state.num++;
                  state.news.add(News(state.num));
                });
              }),
            );
          },
        ),
      ),
      body: OsamBuilder<List<News>>(
        stream: widget.core.propertyStream((state) => state.news),
        builder: (ctx, value) {
          return ListView(
            children: value.map((e) {
              return Row(
                children: <Widget>[
                  Text(e.id.toString()),
                  OsamBuilder<bool>(
                    stream: e.propertyStream((state) => state.isFavorite),
                    builder: (ctx, value) => GestureDetector(
                      child: Icon(value ? Icons.plus_one : Icons.minimize),
                      onTap: () {
                        print(e.hashCode);
                        e.update((state) => state.isFavorite = !value);
                        print(e.hashCode);
                      },
                    ),
                  )
                ],
              );
            }).toList(),
          );
        },
      ),
    );
  }
}

// ignore: must_be_immutable
class Core extends BaseState<Core> {
  var num = 0;
  var news = <News>[];

  @override
  List<Object> get props => [news, num];
}

// ignore: must_be_immutable
class News extends BaseState<News> {
  bool isFavorite = false;
  final id;

  News(this.id);

  @override
  List<Object> get props => [isFavorite, id];
}
2
likes
0
pub points
0%
popularity

Publisher

verified publisherrenesanse.net

Navigation and UI elements which fits with Osam library

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

after_layout, flutter, osam, provider

More

Packages that depend on osam_flutter