sqlite_handler 0.0.4 copy "sqlite_handler: ^0.0.4" to clipboard
sqlite_handler: ^0.0.4 copied to clipboard

Sqlite Handler is a small and light package to deal with the Sqlite database.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sqlite_handler/model.dart';
import 'package:sqlite_handler_example/tables.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  Migrations.createTables(tables);

  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: TextButton(
            child: const Text('Running on: n'),
            onPressed: () async {
              await UserModel(
                      name: "Allen",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "Allen")
                  .insert();

              await UserModel(
                      name: "Teddy",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "Teddy")
                  .insert();

              await UserModel(
                      name: "Mark",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "Mark")
                  .insert();

              await UserModel(
                      name: "James",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "James")
                  .insert();

              await UserModel(
                      name: "Kim",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "Kim")
                  .insert();

              await UserModel(
                      name: "Paul",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: false,
                      createdAt: DateTime.now(),
                      bio: "Paul")
                  .insert();

              await UserModel(
                      name: "ali",
                      email: "[email protected]",
                      password: "123456789",
                      isActive: true,
                      createdAt: DateTime.now(),
                      bio: "annna")
                  .insert();
            },
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            // PersonsModel user = PersonsModel();
            // var all = await user.all();

            // print(all);
            print(await PersonsModel().pluck(['id', 'name']));

            // var a = ['name'];
            // print(a.runtimeType.toString().contains("List<String>"));

            // UserModel a = await UserModel()
            //     .orWhere("id", value: 21)
            //     .limit(2)
            //     .order()
            //     .first();
            // UserModel user = await UserModel().find(1);

            // PersonsModel person = await PersonsModel(
            //   name: "ali",
            //   email: "[email protected]",
            //   password: "123456789",
            //   userId: user.id,
            //   createdAt: DateTime.now(),
            // ).insert();

            // print(await PersonsModel().outerJoin());
            // print(await person.outerJoin());
            // print(a.name);
// print((await UserModel().where("id",value: 21).first()).ali);

            // print(UserModel().fromMap(a[0]));
          },
          child: const Text("click me"),
        ),
      ),
    );
  }
}

class UserModel extends Model {
  int? id;
  String? email, password, name, bio;
  bool? isActive;
  DateTime? createdAt;

  UserModel(
      {this.id,
      this.email,
      this.password,
      this.name,
      this.bio,
      this.createdAt,
      this.isActive})
      : super('users');

  @override
  UserModel fromMap(Map<dynamic, dynamic> map) => UserModel(
        id: map['id'],
        email: map['email'],
        password: map['password'],
        bio: map['bio'],
        name: map['name'],
        isActive: getBool(map['is_active']),
        createdAt: getDateTime(map['created_at']),
      );

  @override
  Map<String, Object?> toMap() => {
        'id': id,
        'email': email,
        'password': password,
        'bio': bio,
        'name': name,
        'is_active': isActive,
        'created_at': createdAt,
      };
}

class PersonsModel extends Model {
  int? id, userId;
  String? email, password, name;
  DateTime? createdAt;

  PersonsModel(
      {this.id,
      this.email,
      this.password,
      this.name,
      this.createdAt,
      this.userId})
      : super('persons');
  // super('persons', );

  @override
  PersonsModel fromMap(Map<dynamic, dynamic> map) => PersonsModel(
        id: map['id'],
        email: map['email'],
        password: map['password'],
        name: map['name'],
        userId: map['user_id'],
        createdAt: getDateTime(map['created_at']),
      );

  @override
  Map<String, Object?> toMap() => {
        'id': id,
        'email': email,
        'password': password,
        'name': name,
        'user_id': userId,
        'created_at': createdAt,
      };
}
2
likes
120
pub points
23%
popularity

Publisher

verified publishermabdulmonem.com

Sqlite Handler is a small and light package to deal with the Sqlite database.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

file_encryptor, flutter, flutter_web_plugins, path, plugin_platform_interface, sqflite

More

Packages that depend on sqlite_handler