Skip to content

Commit

Permalink
Merge pull request #38 from wednesday-solutions/adding_default_cities
Browse files Browse the repository at this point in the history
Adding default cities for both web & mobile
  • Loading branch information
aliHafizji authored Nov 2, 2022
2 parents d35ffa7 + 1e52f24 commit fe285e3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.useAndroidX=true
android.enableJetifier=true
# Flutter specific properties
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
Binary file added assets/pre_populated_cities.sqlite
Binary file not shown.
8 changes: 8 additions & 0 deletions lib/services/base/database/connection/mobile.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:drift/drift.dart';
import 'package:flutter/services.dart';
import 'package:flutter_template/flavors/flavor_config.dart';
import 'package:flutter_template/services/base/database/app_database.dart';
import 'package:path_provider/path_provider.dart';
Expand All @@ -10,6 +11,13 @@ AppDatabase connect() {
final db = LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(p.join(dbFolder.path, 'template_app_db.sqlite'));

if (!await file.exists()) {
final blob = await rootBundle.load('assets/pre_populated_cities.sqlite');
final buffer = blob.buffer;
await file.writeAsBytes(buffer.asUint8List(blob.offsetInBytes, blob.lengthInBytes));
}

return NativeDatabase(
file,
logStatements: FlavorConfig.instance.values.logSqlStatements,
Expand Down
8 changes: 6 additions & 2 deletions lib/services/base/database/connection/web.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

import 'package:drift/web.dart';
import 'package:flutter/services.dart';
import 'package:flutter_template/services/base/database/app_database.dart';

AppDatabase connect() {
return AppDatabase(WebDatabase('db'));
return AppDatabase(WebDatabase('db',
initializer: () async {
return (await rootBundle.load('assets/pre_populated_cities.sqlite')).buffer.asUint8List();
}));
//typedef CreateWebDatabase = FutureOr<Uint8List> Function();
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ flutter:
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - assets/translations/
assets:
- assets/pre_populated_cities.sqlite
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
Expand Down

0 comments on commit fe285e3

Please sign in to comment.