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

A Swift-inspired persistent data management solution for Flutter. Provides simple, powerful, and type-safe way to persist your app's models with automatic UI updates.

example/lib/main.dart

import 'package:cozy_data/cozy_data.dart';
import 'package:cozy_data_example/simple_example/simple_example.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'full_example/full_example.dart';
import 'full_example/model/recipe.dart';
import 'simple_example/model/person.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await CozyData.initialize(
      showLogs: true,
      engine: CozyEngine.memory,
      mappers: [
        PersonMapper.ensureInitialized(),
        RecipeMapper.ensureInitialized()
      ]);
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cozy Data Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        scaffoldBackgroundColor: const Color.fromRGBO(242, 242, 247, 1),
      ),
      home: const Examples(),
    );
  }
}

// Example usage in a Flutter widget
class Examples extends StatefulWidget {
  const Examples({super.key});

  @override
  _ExamplesState createState() => _ExamplesState();
}

class _ExamplesState extends State<Examples> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => const SimpleExample()),
              );
            },
            child: const Text(
              "Simple Example",
              style: TextStyle(color: CupertinoColors.activeBlue),
            ),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => const FullExample(),
                ),
              );
            },
            child: const Text(
              "Full Example",
              style: TextStyle(color: CupertinoColors.activeBlue),
            ),
          ),
        ],
      ),
    ));
  }
}
9
likes
150
points
146
downloads

Publisher

verified publisherdoumbouya.dev

Weekly Downloads

A Swift-inspired persistent data management solution for Flutter. Provides simple, powerful, and type-safe way to persist your app's models with automatic UI updates.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dart_mappable, flutter, logger, path, path_provider, sqflite, sqlite3, synchronized, uuid

More

Packages that depend on cozy_data