flutterx_live_data 2.0.1
flutterx_live_data: ^2.0.1 copied to clipboard
Observable data holders inspired by Android LiveData, with lazy activation, mediators, history, storage, observable collections and widget builders.
import 'package:flutter/material.dart';
import 'package:flutterx_live_data/flutterx_live_data.dart';
void main() => runApp(const ExampleApp());
/// A counter held by a [MutableLiveData], with a parity label derived from it by a transformation.
class ExampleApp extends StatefulWidget {
/// Creates the example app.
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
final _counter = MutableLiveData<int>(value: 0);
late final _parity = _counter.transform((value) => value.isEven ? 'even' : 'odd');
@override
Widget build(BuildContext context) => MaterialApp(
home: Scaffold(
body: Center(
child: LiveDataBuilder<int>(
data: _counter,
builder: (context, value) => LiveDataBuilder<String>(
data: _parity,
builder: (context, parity) => Text('$value is $parity'),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _counter.value++,
child: const Icon(Icons.add),
),
),
);
}