Skip to content

Commit

Permalink
Environment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeFP committed Jan 29, 2021
1 parent 21534bd commit f732841
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MOCK_DATA=false
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart' as DotEnv;

import 'routes.dart';
import 'services/database_service.dart';
import 'views/balance_page.dart';
import 'views/loans_page.dart';
import 'getit.dart';

Future<void> main() async {
void main() async {
await DotEnv.load();
setup();
await getIt<DatabaseService>().setup();
runApp(MyApp());
Expand Down
5 changes: 3 additions & 2 deletions lib/providers/loan_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:loaf_tracker/model/loan.dart';
import 'package:loaf_tracker/model/money_source.dart';
import 'package:loaf_tracker/model/user.dart';
Expand Down Expand Up @@ -46,9 +47,9 @@ class LoanProvider extends ChangeNotifier {
Future<void> loadUser() async {
User user;
if (UserService.testUser.id == null) {
user = await UserService.createUser(UserService.testUser);
user = await UserService.createUser(env['MOCK_DATA'] == 'true' ? UserService.testUser : User());
}
user = await UserService.getUser(UserService.testUser.id);
user = await UserService.getUser(user.id);
_user = user;
_userStream.add(user);
}
Expand Down
13 changes: 9 additions & 4 deletions lib/services/database_service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

Expand All @@ -8,7 +9,7 @@ class DatabaseService {
Future<void> setup() async {
WidgetsFlutterBinding.ensureInitialized();
_database =
openDatabase(join(await getDatabasesPath(), 'cash_loaf_database.db'),
openDatabase(join(await getDatabasesPath(), 'loaf_tracker_database.db'),
onCreate: (db, version) {
return Future.wait([
db.execute(
Expand All @@ -22,11 +23,15 @@ class DatabaseService {
),
]);
}, onOpen: (db) {
return db.execute('DELETE FROM loan; DELETE FROM money_source; DELETE FROM person;');
if (env['MOCK_DATA'] == 'true') {
return db.execute('DELETE FROM loan; DELETE FROM money_source; DELETE FROM person;');
}
}, version: 1);

for(var loaner in LoanService.testLoans) {
await LoanService.createLoaner(loaner);
if (env['MOCK_DATA'] == 'true') {
for(var loaner in LoanService.testLoans) {
await LoanService.createLoaner(loaner);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_dotenv
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
flutter_masked_text:
dependency: "direct main"
description:
Expand Down
33 changes: 3 additions & 30 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies:
sqflite:
path:
collection: ^1.14.13
flutter_dotenv: ^3.1.0

dev_dependencies:
flutter_test:
Expand All @@ -27,33 +28,5 @@ dev_dependencies:
flutter:
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# 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
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
assets:
- .env

0 comments on commit f732841

Please sign in to comment.