local_shared 1.0.0 copy "local_shared: ^1.0.0" to clipboard
local_shared: ^1.0.0 copied to clipboard

A SharedPreferences-based local storage, designed as an alternative to the localstore package

example/lib/main.dart

import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:local_shared/local_shared.dart';

part 'src/collection_crud.dart';
part 'src/document_crud.dart';
part 'src/many_document_crud.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await LocalShared('MY_DB').initialize();

  // ignore: avoid_print
  if (kDebugMode) LocalShared.stream.listen(print);

  runApp(const MaterialApp(
    title: 'Local Shared CRUD',
    home: MyApp(),
  ));
}

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

  @override
  Widget build(BuildContext context) {
    return SelectionArea(
      child: Scaffold(
        body: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Expanded(
              child: Center(
                child: Text(
                  'CRUD EXAMPLE',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 24.0,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
            ),
            ...List.generate(
              3,
              (x) {
                return Container(
                  padding: const EdgeInsets.only(bottom: 20.0),
                  alignment: Alignment.center,
                  child: TextButton.icon(
                    onPressed: () => Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (_) => const [
                                  CollectionCRUD(),
                                  DocumentCRUD(),
                                  ManyDocumentCRUD()
                                ][x])),
                    style: const ButtonStyle(
                      backgroundColor: MaterialStatePropertyAll(Colors.black),
                    ),
                    icon: Icon(
                      [
                        Icons.folder,
                        Icons.book,
                        Icons.collections_bookmark_rounded
                      ][x],
                      color: Colors.white,
                    ),
                    label: SizedBox(
                      width: 150.0,
                      child: Text(
                        ['Collection', 'Document', 'Many Document'][x],
                        style: const TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                );
              },
            ),
            const Spacer(),
          ],
        ),
      ),
    );
  }
}
12
likes
0
pub points
33%
popularity

Publisher

verified publisherinidia.app

A SharedPreferences-based local storage, designed as an alternative to the localstore package

Homepage
Repository (GitHub)
View/report issues

Topics

#utility #storage #database #cache

Funding

Consider supporting this project:

ko-fi.com

License

unknown (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on local_shared