Flow database :
Flow database is a reactive library used to retailer information in the community constructed on most sensible of sqlite database on your cellular apps.
pubspec.yaml :
Upload the specified libraries for the float.
dependencies: float: ^1.7.1 sqlite3_flutter_libs: ^0.5.0 path_provider: ^2.0.0 trail: ^1.8.0
dev_dependencies: drift_dev: ^1.7.0 build_runner: ^2.1.11
information.dart :
import 'bundle:float/float.dart'; section 'information.g.dart'; elegance Merchandise extends Desk { IntColumn get identity => integer().autoIncrement()(); TextColumn get name => textual content()(); TextColumn get description => textual content()(); } summary elegance ProductsView extends View{ Merchandise get merchandise; @override Question as() => make a choice([ products.title ]).from(merchandise); } @DriftDatabase(tables:[ Products ], perspectives:[ ProductsView ]) elegance Database extends _$Database { Database(QueryExecutor e): tremendous(e); @override int get schemaVersion => 2; }
information.g.dart :
That is the generated document for information.dart document.
// GENERATED CODE - DO NOT MODIFY BY HAND a part of 'information.dart'; // ************************************************************************** // MoorGenerator // ************************************************************************** // ignore_for_file: sort=lint elegance Product extends DataClass implements Insertable<Product> { ultimate int identity; ultimate String name; ultimate String description; Product({required this.identity, required this.name, required this.description}); manufacturing facility Product.fromData(Map<String, dynamic> information, {String? prefix}) { ultimate effectivePrefix = prefix ?? ''; go back Product( identity: const IntType() .mapFromDatabaseResponse(information['${effectivePrefix}id'])!, name: const StringType() .mapFromDatabaseResponse(information['${effectivePrefix}title'])!, description: const StringType() .mapFromDatabaseResponse(information['${effectivePrefix}description'])!, ); } @override Map<String, Expression> toColumns(bool nullToAbsent) { ultimate map = <String, Expression>{}; map['id'] = Variable<int>(identity); map['title'] = Variable<String>(name); map['description'] = Variable<String>(description); go back map; } ProductsCompanion toCompanion(bool nullToAbsent) { go back ProductsCompanion( identity: Price(identity), name: Price(name), description: Price(description), ); } manufacturing facility Product.fromJson(Map<String, dynamic> json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; go back Product( identity: serializer.fromJson<int>(json['id']), name: serializer.fromJson<String>(json['title']), description: serializer.fromJson<String>(json['description']), ); } @override Map<String, dynamic> toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; go back <String, dynamic>{ 'identity': serializer.toJson<int>(identity), 'name': serializer.toJson<String>(name), 'description': serializer.toJson<String>(description), }; } Product copyWith({int? identity, String? name, String? description}) => Product( identity: identity ?? this.identity, name: name ?? this.name, description: description ?? this.description, ); @override String toString() { go back (StringBuffer('Product(') ..write('identity: $identity, ') ..write('name: $name, ') ..write('description: $description') ..write(')')) .toString(); } @override int get hashCode => Object.hash(identity, name, description); @override bool operator ==(Object different) => similar(this, different) || (different is Product && different.identity == this.identity && different.name == this.name && different.description == this.description); } elegance ProductsCompanion extends UpdateCompanion<Product> { ultimate Price<int> identity; ultimate Price<String> name; ultimate Price<String> description; const ProductsCompanion({ this.identity = const Price.absent(), this.name = const Price.absent(), this.description = const Price.absent(), }); ProductsCompanion.insert({ this.identity = const Price.absent(), required String name, required String description, }) : name = Price(name), description = Price(description); static Insertable<Product> customized({ Expression<int>? identity, Expression<String>? name, Expression<String>? description, }) { go back RawValuesInsertable({ if (identity != null) 'identity': identity, if (name != null) 'name': name, if (description != null) 'description': description, }); } ProductsCompanion copyWith( {Price<int>? identity, Price<String>? name, Price<String>? description}) { go back ProductsCompanion( identity: identity ?? this.identity, name: name ?? this.name, description: description ?? this.description, ); } @override Map<String, Expression> toColumns(bool nullToAbsent) { ultimate map = <String, Expression>{}; if (identity.provide) { map['id'] = Variable<int>(identity.worth); } if (name.provide) { map['title'] = Variable<String>(name.worth); } if (description.provide) { map['description'] = Variable<String>(description.worth); } go back map; } @override String toString() { go back (StringBuffer('ProductsCompanion(') ..write('identity: $identity, ') ..write('name: $name, ') ..write('description: $description') ..write(')')) .toString(); } } elegance $ProductsTable extends Merchandise with TableInfo<$ProductsTable, Product> { @override ultimate GeneratedDatabase attachedDatabase; ultimate String? _alias; $ProductsTable(this.attachedDatabase, [this._alias]); ultimate VerificationMeta _idMeta = const VerificationMeta('identity'); @override past due ultimate GeneratedColumn<int?> identity = GeneratedColumn<int?>( 'identity', aliasedName, false, sort: const IntType(), requiredDuringInsert: false, defaultConstraints: 'PRIMARY KEY AUTOINCREMENT'); ultimate VerificationMeta _titleMeta = const VerificationMeta('name'); @override past due ultimate GeneratedColumn<String?> name = GeneratedColumn<String?>( 'name', aliasedName, false, sort: const StringType(), requiredDuringInsert: true); ultimate VerificationMeta _descriptionMeta = const VerificationMeta('description'); @override past due ultimate GeneratedColumn<String?> description = GeneratedColumn<String?>( 'description', aliasedName, false, sort: const StringType(), requiredDuringInsert: true); @override Checklist<GeneratedColumn> get $columns => [id, title, description]; @override String get aliasedName => _alias ?? 'merchandise'; @override String get actualTableName => 'merchandise'; @override VerificationContext validateIntegrity(Insertable<Product> example, {bool isInserting = false}) { ultimate context = VerificationContext(); ultimate information = example.toColumns(true); if (information.containsKey('identity')) { context.care for(_idMeta, identity.isAcceptableOrUnknown(information['id']!, _idMeta)); } if (information.containsKey('name')) { context.care for( _titleMeta, name.isAcceptableOrUnknown(information['title']!, _titleMeta)); } else if (isInserting) { context.lacking(_titleMeta); } if (information.containsKey('description')) { context.care for( _descriptionMeta, description.isAcceptableOrUnknown( information['description']!, _descriptionMeta)); } else if (isInserting) { context.lacking(_descriptionMeta); } go back context; } @override Set<GeneratedColumn> get $primaryKey => {identity}; @override Product map(Map<String, dynamic> information, {String? tablePrefix}) { go back Product.fromData(information, prefix: tablePrefix != null ? '$tablePrefix.' : null); } @override $ProductsTable createAlias(String alias) { go back $ProductsTable(attachedDatabase, alias); } } elegance ProductsViewData extends DataClass { ultimate String name; ProductsViewData({required this.name}); manufacturing facility ProductsViewData.fromData(Map<String, dynamic> information, {String? prefix}) { ultimate effectivePrefix = prefix ?? ''; go back ProductsViewData( name: const StringType() .mapFromDatabaseResponse(information['${effectivePrefix}title'])!, ); } manufacturing facility ProductsViewData.fromJson(Map<String, dynamic> json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; go back ProductsViewData( name: serializer.fromJson<String>(json['title']), ); } @override Map<String, dynamic> toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; go back <String, dynamic>{ 'name': serializer.toJson<String>(name), }; } ProductsViewData copyWith({String? name}) => ProductsViewData( name: name ?? this.name, ); @override String toString() { go back (StringBuffer('ProductsViewData(') ..write('name: $name') ..write(')')) .toString(); } @override int get hashCode => name.hashCode; @override bool operator ==(Object different) => similar(this, different) || (different is ProductsViewData && different.name == this.name); } elegance $ProductsViewView extends ViewInfo<$ProductsViewView, ProductsViewData> implements HasResultSet { ultimate String? _alias; @override ultimate _$Database attachedDatabase; $ProductsViewView(this.attachedDatabase, [this._alias]); $ProductsTable get merchandise => attachedDatabase.merchandise.createAlias('t0'); @override Checklist<GeneratedColumn> get $columns => [products.title]; @override String get aliasedName => _alias ?? entityName; @override String get entityName => 'products_view'; @override String? get createViewStmt => null; @override $ProductsViewView get asDslTable => this; @override ProductsViewData map(Map<String, dynamic> information, {String? tablePrefix}) { go back ProductsViewData.fromData(information, prefix: tablePrefix != null ? '$tablePrefix.' : null); } past due ultimate GeneratedColumn<String?> name = GeneratedColumn<String?>( 'name', aliasedName, false, sort: const StringType()); @override $ProductsViewView createAlias(String alias) { go back $ProductsViewView(attachedDatabase, alias); } @override Question? get question => (attachedDatabase.selectOnly(merchandise, includeJoinedTableColumns: false) ..addColumns($columns)); @override Set<String> get readTables => const {'merchandise'}; } summary elegance _$Database extends GeneratedDatabase { _$Database(QueryExecutor e) : tremendous(SqlTypeSystem.defaultInstance, e); past due ultimate $ProductsTable merchandise = $ProductsTable(this); past due ultimate $ProductsViewView productsView = $ProductsViewView(this); @override Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>(); @override Checklist<DatabaseSchemaEntity> get allSchemaEntities => [products, productsView]; }
primary.dart :
Offering the entire code for implementation for float database.
import 'bundle:float/local.dart'; import 'information.dart'; Long term<void> primary() async { ultimate db = Database(NativeDatabase.reminiscence()); look forward to db.into(db.merchandise).insert(ProductsCompanion.insert(name: "flutter float", description: "Flow database")); look forward to db.into(db.merchandise).insert(ProductsCompanion.insert(name: "educational on float", description: "Flow database")); (look forward to db.make a choice(db.merchandise).get()).forEach(print); }
output :