flutterx_live_data 1.0.4-dev flutterx_live_data: ^1.0.4-dev copied to clipboard
LiveData is a data holder class that can be observed. This is a Flutter implementation of LiveData in Android Jetpack library
import 'package:flutter/material.dart';
import 'package:flutterx_live_data/flutterx_live_data.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutterx LiveData Demo',
theme: ThemeData(primarySwatch: Colors.teal),
home: const LiveDataExample());
}
class LiveDataExample extends StatefulWidget {
const LiveDataExample({Key? key}) : super(key: key);
@override
State<LiveDataExample> createState() => _LiveDataExampleState();
}
class _LiveDataExampleState extends State<LiveDataExample> {
final MutableLiveData<int> myCounter = MutableLiveData(initialValue: 0);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('LiveData example')),
body: Center(
child: LiveDataBuilder<int>(data: myCounter, builder: (context, value) => Text('pressed $value times'))),
floatingActionButton: FloatingActionButton(onPressed: () => myCounter.value++, child: const Icon(Icons.add)));
}