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

outdated

Live Data in Flutter

example/lib/main.dart

import 'dart:async';

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Live Data',
      theme: ThemeData(
        primarySwatch: Colors.lightGreen,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => HomePageState();
}

class HomePageState extends State<HomePage> {
  LiveData liveData;

  HomePageState() {
    liveData = LiveData<int>(0);

    Timer.periodic(Duration(seconds: 1), (timer) {
      liveData.value += 1;
    });
  }

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

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: liveData.stream,
      builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
        return Text('count: ${snapshot.data}');
      },
    );
  }
}
8
likes
30
pub points
75%
popularity

Publisher

unverified uploader

Live Data in Flutter

Homepage

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_live_data