get_storage 1.2.0 copy "get_storage: ^1.2.0" to clipboard
get_storage: ^1.2.0 copied to clipboard

outdated

A fast, extra light and synchronous key-value storage written entirely in Dart

example/lib/main.dart

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

void main() async {
  await GetStorage.init();
  runApp(App());
}

class App extends StatelessWidget {
  final box = GetStorage();

  @override
  Widget build(BuildContext context) {
    // We will insert a value into the storage if it does not already have one, otherwise it will ignore it.
    box.writeIfNull('darkmode', false);

    // ValueListenableBuilder is a Flutter widget
    return ValueListenableBuilder(
        valueListenable: box.listenable,
        builder: (c, read, w) {
          bool isDark = box.read('darkmode');
          print(read['darkmode']); // its work too
          return MaterialApp(
            theme: isDark ? ThemeData.dark() : ThemeData.light(),
            home: Scaffold(
              appBar: AppBar(title: Text("Get Storage")),
              body: Center(
                child: SwitchListTile(
                  value: isDark,
                  title: Text("Touch to change ThemeMode"),
                  onChanged: (val) => box.write('darkmode', val),
                ),
              ),
            ),
          );
        });
  }
}
1625
likes
0
pub points
99%
popularity

Publisher

verified publishergetx.site

A fast, extra light and synchronous key-value storage written entirely in Dart

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

file, flutter, path_provider

More

Packages that depend on get_storage