Skip to content

ChristianMaidhof/flutter_localstorage

 
 

Repository files navigation

LocalStorage

LocalStorage for Flutter.

Important

LocalStorage is not intended to store large amounts or sensitive data.

Installation

flutter pub add localstorage

or add dependency to pubspec.yaml manually

dependencies:
  localstorage: ^5.0.0

API docs

LocalStorage API documentation

Usage

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

late final ValueNotifier<int> notifier;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initLocalStorage();

  notifier = ValueNotifier(int.parse(localStorage.getItem('counter') ?? '0'));
  notifier.addListener(() {
    localStorage.setItem('counter', notifier.value.toString());
  });

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ValueListenableBuilder<int>(
            valueListenable: notifier,
            builder: (context, value, child) {
              return Text('Pressed $value times');
            },
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            notifier.value++;
          },
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

License

MIT

About

📦 LocalStorage for Flutter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 42.4%
  • CMake 34.7%
  • Dart 8.5%
  • Ruby 5.0%
  • Swift 3.3%
  • HTML 3.3%
  • Other 2.8%