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

discontinued
outdated

Navigation and UI elements which fits with Osam library

example/lib/main.dart

import 'dart:async';

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

final navKey = GlobalKey<NavigatorState>();

void main() async {
  final core = Core();
  runApp(MaterialApp(
    navigatorKey: navKey,
    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: () {
          widget.core.news = [News(1)];
          widget.core.c.add(widget.core.news);
        },
      ),
      body: OsamBuilder<List<News>>(
          stream: widget.core.stream,
          builder: (context, snapshot) {
            return ListView(
              children: snapshot
                  .map((e) => Row(
                        key: ValueKey(e.id),
                        children: <Widget>[
                          Container(
                            height: 600,
                            child: OsamBuilder(
                              stream: e.stream,
                              builder: (ctx, data) => Text(data.toString()),
                            ),
                          ),
                          RaisedButton(
                            onPressed: () {
                              e.isFavorite = !e.isFavorite;
                              e.c.add(e.isFavorite);
                            },
                          )
                        ],
                      ))
                  .toList(),
            );
          }),
    );
  }
}

class Core {
  var num = 0;
  var news = <News>[News(1), News(2), News(3)];

  StreamController<List<News>> c;

  init() {
    c = StreamController<List<News>>.broadcast(onCancel: () {
      c.close();
      c = null;
    });
  }

  ValueStream<List<News>> get stream => ValueStream(c.stream, news);

  Core(){
    init();
  }
}

class News {
  bool isFavorite = false;
  final int id;

  StreamController<bool> c;

  ValueStream<bool> get stream => ValueStream(c.stream, isFavorite);

  init() {
    c = StreamController<bool>.broadcast(onCancel: () {
      c.close();
      c = null;
    });
  }

  News(this.id){
    init();
  }
}
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