flutter_persistence 0.0.7 copy "flutter_persistence: ^0.0.7" to clipboard
flutter_persistence: ^0.0.7 copied to clipboard

A Flutter library for efficient data persistence using Hive as a local storage solution.

example/main.dart

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

void main() async {
  // Initialize Flutter Persistence before running the app.
  await FlutterPersistence.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  // A fake asynchronous stream generator for demonstration purposes.
  Stream<int> buildFakeStream() async* {
    await Future.delayed(const Duration(seconds: 3));
    for (int i = 0; i < 10; i++) {
      await Future.delayed(const Duration(seconds: 1));
      yield i;
    }
  }

  @override
  Widget build(BuildContext context) {
    // Generate the fake stream and persist it using Flutter Persistence.
    final myStream = buildFakeStream();
    final persistedStream =
        FlutterPersistence.stream(key: "fakeStream", stream: myStream);

    return Scaffold(
      appBar: AppBar(
        title: const Text("Flutter Persistence"),
      ),
      body: StreamBuilder(
        stream: persistedStream,
        builder: (context, snap) {
          if (snap.hasData) {
            // Display the data from the persisted stream.
            return Text(snap.data.toString());
          } else if (snap.hasError) {
            // Handle and display any errors that occur during streaming.
            return Text(snap.error.toString());
          }
          // Display an empty container while waiting for data.
          return Container();
        },
      ),
    );
  }
}
6
likes
0
pub points
29%
popularity

Publisher

unverified uploader

A Flutter library for efficient data persistence using Hive as a local storage solution.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, flutter, hive, hive_flutter

More

Packages that depend on flutter_persistence