osam 6.4.2 copy "osam: ^6.4.2" to clipboard
osam: ^6.4.2 copied to clipboard

discontinued

Lightweight and predictable state management. Allows you to save all application state by using Hve library

example/lib/main.dart

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

part 'main.g.dart';

@HiveType(typeId: 0)
class Counter extends PropertyChanger {
  @HiveField(0)
  final IProperty<int> value;

  void increment() => let(value).apply((value) => value++);

  Counter({IProperty<int> value}) : value = value ?? IProperty(0);
}

final persist = Persist<Counter, Null>(appName: '123');

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  Hive.registerAdapter(CounterAdapter());
  registerOsamAdapters();
  await persist.init();
  final counter = persist.appState ?? Counter();
  runApp(Example(counter: counter));
}

class Example extends StatelessWidget {
  final Counter counter;

  const Example({Key key, this.counter}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {
            counter.increment();
            persist.save(state: counter, uiState: null, version: null);
          },
        ),
        body: Center(
          child: ValueListenableBuilder(
            valueListenable: counter.value,
            builder: (_, value, __) => Text(
              value.toString(),
              style: const TextStyle(fontSize: 40),
            ),
          ),
        ),
      ),
    );
  }
}
9
likes
35
points
15
downloads

Publisher

verified publisherrenesanse.net

Weekly Downloads

Lightweight and predictable state management. Allows you to save all application state by using Hve library

Homepage

License

MIT (license)

Dependencies

equatable, flutter, hive, hive_flutter, path_provider

More

Packages that depend on osam