flora_orm 2.0.20 copy "flora_orm: ^2.0.20" to clipboard
flora_orm: ^2.0.20 copied to clipboard

Flutter plugin for ORM in front of storage like sqflite and shared_preferences

example/lib/main.dart

import 'package:example/user.entity.dart';
import 'package:flora_orm/flora_orm.dart';
import 'package:flutter/material.dart';

void main() {
  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(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  /// we recommened you instatiate and register OrmManager as singleton
  final orm = OrmManager(
    dbVersion: 1,
    dbName: 'orm_db_test.db',
    tables: <Entity>[
      /// You must register all entities you intend to save here
      UserEntity(),
    ],
  );

  /// Get a storage instance of the Entity type you want to use.
  /// **IMPORTANT remember to specify type ([UserEntityOrm] for this example)
  /// to make your life easier when using storage object
  late final UserEntityOrm storage = orm.getStorage(UserEntity());

  Future<UserEntity> _insertUser() async {
    await storage.insertOrUpdate(
      UserEntity(
        id: 'user1',
        firstName: 'John',
        lastName: 'Doe',
      ),
    );

    final user = await storage.firstWhereOrNull(
      where: (t) => Filter(t.lastName, value: 'Doe'),
    );
    return user!;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: FutureBuilder(
          future: _insertUser(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) {
              return const Text('Loading...');
            }
            final user = snapshot.data!;
            return Text('Hello, ${user.firstName} ${user.lastName}');
          },
        ),
      ),
    );
  }
}
2
likes
130
points
380
downloads

Publisher

verified publishertatlacas.com

Weekly Downloads

Flutter plugin for ORM in front of storage like sqflite and shared_preferences

Repository (GitHub)
View/report issues

Topics

#sql #database #orm #storage #persistence

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

analyzer, build, build_config, collection, equatable, flutter, flutter_lints, meta, path, path_provider, pubspec_dependency_sorter, shared_preferences, source_gen, sqflite, sqflite_common, sqflite_common_ffi, uuid

More

Packages that depend on flora_orm