Skip to content

Commit

Permalink
dependency clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
andreacioni committed Apr 16, 2022
1 parent 4b9a770 commit cc9cb25
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-5.2.0/","dependencies":[]},{"name":"path_provider_ios","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.8/","dependencies":[]},{"name":"shared_preferences_ios","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.1.0/","dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-5.2.0/","dependencies":[]},{"name":"path_provider_android","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.12/","dependencies":[]},{"name":"shared_preferences_android","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.11/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.5/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.5/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.1.0/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.5/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.1.0/","dependencies":["path_provider_windows"]}],"web":[{"name":"flutter_keyboard_visibility_web","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility_web-2.0.0/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.3/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":["flutter_keyboard_visibility_web"]},{"name":"flutter_keyboard_visibility_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-04-14 22:10:46.203728","version":"2.10.3"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-5.2.0/","dependencies":[]},{"name":"path_provider_ios","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_ios-2.0.8/","dependencies":[]},{"name":"shared_preferences_ios","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_ios-2.1.0/","dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-5.2.0/","dependencies":[]},{"name":"path_provider_android","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.12/","dependencies":[]},{"name":"shared_preferences_android","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_android-2.0.11/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.5/","dependencies":[]},{"name":"shared_preferences_macos","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.3/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.1.5/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.1.0/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.5/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.1.0/","dependencies":["path_provider_windows"]}],"web":[{"name":"flutter_keyboard_visibility_web","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility_web-2.0.0/","dependencies":[]},{"name":"shared_preferences_web","path":"/Users/andreacioni/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.3/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":["flutter_keyboard_visibility_web"]},{"name":"flutter_keyboard_visibility_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_ios","shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_ios","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2022-04-16 17:04:50.340777","version":"2.10.4"}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

## Disable CORS for Web development
https://pub.dev/packages/flutter_cors
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.weekly_menu_app"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</style>
<!-- You can name this style whatever you'd like -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/[your_normal_background_drawable]</item>
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
5 changes: 3 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.2.1'
}
}

allprojects {
repositories {
google()
jcenter()
google()
}
}

Expand Down
29 changes: 16 additions & 13 deletions lib/models/base_model.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:async';
import 'dart:io';
import 'dart:io' as io;
import 'package:http/http.dart' as http;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:http/io_client.dart';

import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_data/flutter_data.dart';

import 'package:json_annotation/json_annotation.dart';
Expand All @@ -14,6 +12,8 @@ import 'package:weekly_menu_app/services/auth_service.dart';

import '../globals/constants.dart';

final _providerContainer = ProviderContainer();

abstract class BaseModel<T extends DataModel<T>>
with DataModel<T>
implements Cloneable<T> {
Expand All @@ -38,21 +38,24 @@ mixin BaseAdapter<T extends DataModel<T>> on RemoteAdapter<T> {
static const BASE_URL = "https://heroku-weeklymenu.herokuapp.com/api/v1/";
static const CONNECTION_TIMEOUT = const Duration(seconds: 3);

final _providerContainer = ProviderContainer();

@override
String get baseUrl => BASE_URL;

@override
http.Client get httpClient {
final _httpClient = HttpClient();
final _ioClient = IOClient(_httpClient);

// decrease the timeout
_httpClient.connectionTimeout = CONNECTION_TIMEOUT;
_httpClient.idleTimeout = CONNECTION_TIMEOUT;
FutureOr<Map<String, dynamic>> get defaultParams => {'per_page': 1000};

return _ioClient;
@override
http.Client get httpClient {
if (kIsWeb) {
return http.Client();
} else {
final _httpClient = HttpClient();
final _ioClient = IOClient(_httpClient);
// decrease the timeout
_httpClient.connectionTimeout = CONNECTION_TIMEOUT;
_httpClient.idleTimeout = CONNECTION_TIMEOUT;
return _ioClient;
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/models/shopping_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part 'shopping_list.g.dart';
@DataRepository([BaseAdapter, ShoppingListAdapter])
@CopyWith()
class ShoppingList extends BaseModel<ShoppingList> {
@JsonKey(defaultValue: const [])
@JsonKey()
List<ShoppingListItem> items;

@JsonKey(includeIfNull: false)
Expand Down
2 changes: 1 addition & 1 deletion lib/models/shopping_list.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions lib/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:dio/dio.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../globals/constants.dart';
Expand All @@ -11,8 +10,6 @@ import '../models/auth_token.dart';
final authServiceProvider = Provider((ref) => AuthService());

class AuthService {
static final _log = Logger();

static final String BASE_URL =
'https://heroku-weeklymenu.herokuapp.com/api/v1';

Expand Down Expand Up @@ -113,30 +110,30 @@ class AuthService {

Future<AuthToken?> get token async {
if (!_initialized) {
_log.i("Auth service not yet initialized");
print("Auth service not yet initialized");
try {
await _loadUserInformation();
_initialized = true;
} catch (e) {
_log.e("There was an error loading saved credentials");
print("There was an error loading saved credentials");
throw e;
}
}

if (_token == null || !_token!.isValid) {
_log.i("Invalid cached token, getting new one...");
print("Invalid cached token, getting new one...");

try {
await _tryLogin();
} on DioError catch (e) {
if (e.type == DioErrorType.response && e.response!.statusCode == 401) {
_log.i(
print(
"Failed auto login with saved credentials, password changed. Login again...");
} else {
_log.e("Unexpented failure while logging in", e);
print("Unexpented failure while logging in\n${e.stackTrace}");
}
} catch (e) {
_log.e("Generic error raised while logging in", e);
print("Generic error raised while logging in\n$e");
}
}

Expand All @@ -147,7 +144,7 @@ class AuthService {
if (_password != null && _email != null) {
await login(_email!, _password!);
} else {
_log.w("email & password are null");
print("email & password are null");
}
}
}
6 changes: 1 addition & 5 deletions lib/widgets/ingredients_screen/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IngredientsScreen extends HookConsumerWidget {
),
],
),
onDismissed: (_) => _deleteIngredient(context, model[index]),
onDismissed: (_) => model[index].delete(),
);
},
itemCount: model.length,
Expand Down Expand Up @@ -91,8 +91,4 @@ class IngredientsScreen extends HookConsumerWidget {
],
);
}

void _deleteIngredient(BuildContext context, Ingredient ingredient) {
ingredient.delete();
}
}
1 change: 0 additions & 1 deletion lib/widgets/menu_editor/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_data/flutter_data.dart' hide Provider;
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:logger/logger.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:objectid/objectid.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down
2 changes: 0 additions & 2 deletions lib/widgets/menu_editor/scroll_view.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_data/flutter_data.dart' hide Provider;
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logger/logger.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:objectid/objectid.dart';
import 'package:weekly_menu_app/globals/hooks.dart';
import 'package:weekly_menu_app/widgets/menu_editor/screen.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/menu_page/menu_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_data/flutter_data.dart' hide Provider;
import 'package:logger/logger.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:collection/collection.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/recipe_view/number_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class NumberFormField extends StatefulWidget {
final String labelText;
final double minValue;
final double maxValue;
final double initialValue;
final double? initialValue;
final bool allowEmpty;
final int fractionDigits;
final void Function(double)? onChanged;
final void Function(double)? onSaved;

NumberFormField({
required this.initialValue,
this.initialValue,
required this.labelText,
String? hintText,
this.minValue = 0,
Expand All @@ -35,7 +35,7 @@ class _NumberFormFieldState extends State<NumberFormField> {
@override
void initState() {
_controller = new TextEditingController(
text: widget.initialValue.toStringAsFixed(widget.fractionDigits));
text: widget.initialValue?.toStringAsFixed(widget.fractionDigits));
_focusNode = new FocusNode();

_focusNode.addListener(_onFocusChange);
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/recipe_view/recipe_information_tiles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RecipeInformationTiles extends StatelessWidget {
),
editingEnabled: editEnabled,
suffix: "min",
minValue: 1,
onChanged: () => {}, //_recipe.setEdited(),
onSaved: (newValue) => originator.update(originator.instance
.copyWith(estimatedPreparationTime: newValue.truncate())),
Expand All @@ -53,6 +54,7 @@ class RecipeInformationTiles extends StatelessWidget {
),
editingEnabled: editEnabled,
suffix: "min",
minValue: 1,
onChanged: () => {}, //_recipe.setEdited(),
onSaved: (newValue) => originator.update(originator.instance
.copyWith(estimatedCookingTime: newValue.truncate())),
Expand Down Expand Up @@ -209,7 +211,7 @@ class EditableInformationTile extends StatelessWidget {
return ListTile(
title: editingEnabled
? NumberFormField(
initialValue: value ?? 0,
initialValue: value,
fractionDigits: 0,
labelText: title,
minValue: minValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_data/flutter_data.dart' hide Provider;
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logger/logger.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../main.data.dart';
Expand All @@ -11,8 +10,6 @@ import '../../../models/ingredient.dart';
import '../../../models/recipe.dart';

class RecipeIngredientListTile extends HookConsumerWidget {
final log = Logger();

final RecipeOriginator _recipe;
final RecipeIngredient recipeIngredient;
final bool editEnabled;
Expand Down Expand Up @@ -101,7 +98,7 @@ class RecipeIngredientListTile extends HookConsumerWidget {

_recipe.update(_recipe.instance.copyWith(ingredients: recipeIngredients));
} else {
log.i("No update ingredient recipe returned");
print("No update ingredient recipe returned");
}
}
}
Loading

0 comments on commit cc9cb25

Please sign in to comment.