Complete recipes page
@@ -47,7 +47,8 @@ android {
|
|||||||
applicationId "com.example.one_trip"
|
applicationId "com.example.one_trip"
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion 18
|
||||||
|
compileSdkVersion 33
|
||||||
targetSdkVersion flutter.targetSdkVersion
|
targetSdkVersion flutter.targetSdkVersion
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.one_trip">
|
package="com.example.one_trip">
|
||||||
<application
|
<application
|
||||||
android:label="one_trip"
|
android:label="One Trip"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 564 B After Width: | Height: | Size: 624 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 981 B |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 6.2 KiB |
@@ -1,3 +1,4 @@
|
|||||||
|
// const String baseURL = "https://groceries.alaevens.ca";
|
||||||
const String baseURL = "http://192.168.0.16:8000";
|
const String baseURL = "http://192.168.0.16:8000";
|
||||||
|
|
||||||
const int resultsPerPage = 4;
|
const int resultsPerPage = 4;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'package:one_trip/api/auth.dart';
|
|
||||||
import 'package:one_trip/api/consts.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
class Ingredient {
|
|
||||||
int id;
|
|
||||||
String name;
|
|
||||||
bool inStock;
|
|
||||||
int contentType;
|
|
||||||
int objectID;
|
|
||||||
|
|
||||||
Ingredient({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
required this.inStock,
|
|
||||||
required this.contentType,
|
|
||||||
required this.objectID,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory Ingredient.fromJson(Map<String, dynamic> json) {
|
|
||||||
return Ingredient(
|
|
||||||
id: json["id"] as int,
|
|
||||||
name: json["name"] as String,
|
|
||||||
inStock: json["in_stock"] as bool,
|
|
||||||
contentType: json["content_type"] as int,
|
|
||||||
objectID: json["object_id"] as int);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
74
one_trip/lib/api/models/listingredient.dart
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:one_trip/api/auth.dart';
|
||||||
|
import 'package:one_trip/api/consts.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
class RecipeIngredient {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
int list;
|
||||||
|
bool inCart;
|
||||||
|
|
||||||
|
RecipeIngredient({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.list,
|
||||||
|
required this.inCart,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory RecipeIngredient.fromJson(Map<String, dynamic> json) {
|
||||||
|
return RecipeIngredient(
|
||||||
|
id: json["id"] as int,
|
||||||
|
name: json["name"] as String,
|
||||||
|
list: json["list"] as int,
|
||||||
|
inCart: json["in_cart"] as bool,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecipeIngredient?> create(String name, int recipeID) async {
|
||||||
|
const String requestURL = "$baseURL/api/listingredients/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
http.Response response = await http.post(
|
||||||
|
Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"},
|
||||||
|
body: {
|
||||||
|
"name": name,
|
||||||
|
"recipe": "$recipeID",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 201) {
|
||||||
|
return RecipeIngredient.fromJson(jsonDecode(response.body));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<RecipeIngredient?> patch(String name) async {
|
||||||
|
String requestURL = "$baseURL/api/listingredients/$id/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
|
||||||
|
http.Response response = await http.patch(Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"}, body: {"name": name});
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return RecipeIngredient.fromJson(jsonDecode(response.body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> delete() async {
|
||||||
|
String requestURL = "$baseURL/api/listingredients/$id/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
http.Response response = await http.delete(Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"});
|
||||||
|
|
||||||
|
if (response.statusCode == 204) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,14 @@ import 'dart:convert';
|
|||||||
import 'package:one_trip/api/auth.dart';
|
import 'package:one_trip/api/auth.dart';
|
||||||
import 'package:one_trip/api/consts.dart';
|
import 'package:one_trip/api/consts.dart';
|
||||||
import 'package:one_trip/api/models/homegroup.dart';
|
import 'package:one_trip/api/models/homegroup.dart';
|
||||||
import 'package:one_trip/api/models/ingredient.dart';
|
import 'package:one_trip/api/models/recipeingredient.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
class Recipe {
|
class Recipe {
|
||||||
int id;
|
int id;
|
||||||
int homegroup;
|
int homegroup;
|
||||||
String name;
|
String name;
|
||||||
List<Ingredient> ingredients;
|
List<RecipeIngredient> ingredients;
|
||||||
|
|
||||||
Recipe(
|
Recipe(
|
||||||
{required this.id,
|
{required this.id,
|
||||||
@@ -19,9 +19,9 @@ class Recipe {
|
|||||||
required this.homegroup});
|
required this.homegroup});
|
||||||
|
|
||||||
factory Recipe.fromJson(Map<String, dynamic> json) {
|
factory Recipe.fromJson(Map<String, dynamic> json) {
|
||||||
List<Ingredient> ingredients = [];
|
List<RecipeIngredient> ingredients = [];
|
||||||
for (dynamic ingredient in json["ingredients"]) {
|
for (dynamic ingredient in json["ingredients"]) {
|
||||||
ingredients.add(Ingredient.fromJson(ingredient));
|
ingredients.add(RecipeIngredient.fromJson(ingredient));
|
||||||
}
|
}
|
||||||
return Recipe(
|
return Recipe(
|
||||||
id: json["id"] as int,
|
id: json["id"] as int,
|
||||||
@@ -56,10 +56,13 @@ class Recipe {
|
|||||||
for (int recipeID in group.recipes) {
|
for (int recipeID in group.recipes) {
|
||||||
Recipe? recipe = await Recipe.get(recipeID);
|
Recipe? recipe = await Recipe.get(recipeID);
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
|
// TODO: implement sorted insert
|
||||||
recipes.add(recipe);
|
recipes.add(recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recipes.sort(((a, b) => a.name.compareTo(b.name)));
|
||||||
|
|
||||||
return recipes;
|
return recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +81,19 @@ class Recipe {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> delete() async {
|
||||||
|
String requestURL = "$baseURL/api/recipes/$id/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
final http.Response response = await http.delete(
|
||||||
|
Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 204) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
one_trip/lib/api/models/recipeingredient.dart
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:one_trip/api/auth.dart';
|
||||||
|
import 'package:one_trip/api/consts.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
class RecipeIngredient {
|
||||||
|
int id;
|
||||||
|
String name;
|
||||||
|
int recipe;
|
||||||
|
|
||||||
|
RecipeIngredient({
|
||||||
|
required this.id,
|
||||||
|
required this.name,
|
||||||
|
required this.recipe,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory RecipeIngredient.fromJson(Map<String, dynamic> json) {
|
||||||
|
return RecipeIngredient(
|
||||||
|
id: json["id"] as int,
|
||||||
|
name: json["name"] as String,
|
||||||
|
recipe: json["recipe"] as int,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<RecipeIngredient?> create(String name, int recipeID) async {
|
||||||
|
const String requestURL = "$baseURL/api/recipeingredients/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
http.Response response = await http.post(
|
||||||
|
Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"},
|
||||||
|
body: {
|
||||||
|
"name": name,
|
||||||
|
"recipe": "$recipeID",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 201) {
|
||||||
|
return RecipeIngredient.fromJson(jsonDecode(response.body));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<RecipeIngredient?> patch(String name) async {
|
||||||
|
String requestURL = "$baseURL/api/recipeingredients/$id/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
|
||||||
|
http.Response response = await http.patch(Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"}, body: {"name": name});
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return RecipeIngredient.fromJson(jsonDecode(response.body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> delete() async {
|
||||||
|
String requestURL = "$baseURL/api/recipeingredients/$id/";
|
||||||
|
String token = TokenSingleton().getToken();
|
||||||
|
http.Response response = await http.delete(Uri.parse(requestURL),
|
||||||
|
headers: {"Authorization": "Token $token"});
|
||||||
|
|
||||||
|
if (response.statusCode == 204) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
52
one_trip/lib/pages/list_page/list_page.dart
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// import 'package:flutter/material.dart';
|
||||||
|
// import 'package:one_trip/api/models/recipe.dart';
|
||||||
|
// import 'package:one_trip/api/models/user.dart';
|
||||||
|
// import 'package:one_trip/pages/recipes_page/widgets/recipe_card_widget.dart';
|
||||||
|
// import 'package:one_trip/widgets/text_entry_dialog.dart';
|
||||||
|
|
||||||
|
// class RecipesPage extends StatefulWidget {
|
||||||
|
// const RecipesPage({super.key});
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// State<RecipesPage> createState() => _RecipesPageState();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// class _RecipesPageState extends State<RecipesPage> {
|
||||||
|
// late Future<List<Recipe>> _recipes;
|
||||||
|
// late User _userInfo;
|
||||||
|
|
||||||
|
// Future<List<Recipe>> _fetchList() async {
|
||||||
|
// User? userInfo = await User.getMe();
|
||||||
|
// if (userInfo == null || userInfo.homegroup == null) {
|
||||||
|
// return [];
|
||||||
|
// }
|
||||||
|
// _userInfo = userInfo;
|
||||||
|
|
||||||
|
// List<Recipe> recipes = await Recipe.getList(_userInfo.homegroup!);
|
||||||
|
// return recipes;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// void initState() {
|
||||||
|
// super.initState();
|
||||||
|
// _recipes = _fetchList();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// Widget build(BuildContext context) {
|
||||||
|
// return FutureBuilder(
|
||||||
|
// future: _recipes,
|
||||||
|
// builder: (context, snapshot) {
|
||||||
|
// if (snapshot.hasError) {
|
||||||
|
// return Text(snapshot.error.toString());
|
||||||
|
// } else if (snapshot.hasData &&
|
||||||
|
// snapshot.connectionState == ConnectionState.done) {
|
||||||
|
// return RecipeList(
|
||||||
|
// recipes: snapshot.data!, homegroup: _userInfo.homegroup!);
|
||||||
|
// } else {
|
||||||
|
// return const Center(child: CircularProgressIndicator());
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
@@ -16,6 +16,12 @@ class _InviteHomegroupDialogState extends State<InviteHomegroupDialog> {
|
|||||||
ListViewState _listState = ListViewState.inactive;
|
ListViewState _listState = ListViewState.inactive;
|
||||||
List<int> selectedIDs = [];
|
List<int> selectedIDs = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_searchController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
|
|||||||
@@ -32,20 +32,17 @@ class ProfileCard extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: [
|
children: [
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Colors.black,
|
||||||
radius: 42,
|
radius: 42,
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: 40,
|
radius: 40,
|
||||||
backgroundImage: userInfo.imageUrl != null
|
backgroundImage: userInfo.imageUrl != null
|
||||||
? NetworkImage(userInfo.imageUrl!)
|
? NetworkImage(userInfo.imageUrl!)
|
||||||
: Image(
|
: const Image(
|
||||||
image: Svg('assets/images/person.svg',
|
image: Svg('assets/images/person.svg',
|
||||||
color: Theme.of(context)
|
color: Colors.black),
|
||||||
.colorScheme
|
|
||||||
.onPrimaryContainer),
|
|
||||||
).image,
|
).image,
|
||||||
backgroundColor:
|
backgroundColor: Colors.white,
|
||||||
Theme.of(context).colorScheme.primaryContainer,
|
|
||||||
// https://github.com/flutter/flutter/issues/42901#issuecomment-708050484
|
// https://github.com/flutter/flutter/issues/42901#issuecomment-708050484
|
||||||
child: Material(
|
child: Material(
|
||||||
shape: const CircleBorder(),
|
shape: const CircleBorder(),
|
||||||
|
|||||||
@@ -16,16 +16,14 @@ class SmallUserChip extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: baseRadius,
|
radius: baseRadius,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Colors.black,
|
||||||
child: CircleAvatar(
|
child: CircleAvatar(
|
||||||
radius: baseRadius - 2,
|
radius: baseRadius - 2,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
backgroundColor: Colors.white,
|
||||||
backgroundImage: user.imageUrl != null
|
backgroundImage: user.imageUrl != null
|
||||||
? NetworkImage(user.imageUrl!)
|
? NetworkImage(user.imageUrl!)
|
||||||
: Image(
|
: const Image(
|
||||||
image: Svg('assets/images/person.svg',
|
image: Svg('assets/images/person.svg', color: Colors.black),
|
||||||
color:
|
|
||||||
Theme.of(context).colorScheme.onPrimaryContainer),
|
|
||||||
).image,
|
).image,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:one_trip/api/models/homegroup.dart';
|
|
||||||
import 'package:one_trip/api/models/recipe.dart';
|
import 'package:one_trip/api/models/recipe.dart';
|
||||||
import 'package:one_trip/api/models/user.dart';
|
import 'package:one_trip/api/models/user.dart';
|
||||||
import 'package:one_trip/pages/recipes_page/widgets/recipe_card_widget.dart';
|
import 'package:one_trip/pages/recipes_page/widgets/recipe_card_widget.dart';
|
||||||
@@ -14,16 +13,17 @@ class RecipesPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _RecipesPageState extends State<RecipesPage> {
|
class _RecipesPageState extends State<RecipesPage> {
|
||||||
late Future<List<Recipe>> _recipes;
|
late Future<List<Recipe>> _recipes;
|
||||||
late User _userInfo;
|
User? _userInfo;
|
||||||
|
|
||||||
Future<List<Recipe>> _fetchList() async {
|
Future<List<Recipe>> _fetchList() async {
|
||||||
User? userInfo = await User.getMe();
|
User? userInfo = await User.getMe();
|
||||||
|
_userInfo = userInfo;
|
||||||
|
|
||||||
if (userInfo == null || userInfo.homegroup == null) {
|
if (userInfo == null || userInfo.homegroup == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
_userInfo = userInfo;
|
|
||||||
|
|
||||||
List<Recipe> recipes = await Recipe.getList(_userInfo.homegroup!);
|
List<Recipe> recipes = await Recipe.getList(userInfo.homegroup!);
|
||||||
return recipes;
|
return recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +42,18 @@ class _RecipesPageState extends State<RecipesPage> {
|
|||||||
return Text(snapshot.error.toString());
|
return Text(snapshot.error.toString());
|
||||||
} else if (snapshot.hasData &&
|
} else if (snapshot.hasData &&
|
||||||
snapshot.connectionState == ConnectionState.done) {
|
snapshot.connectionState == ConnectionState.done) {
|
||||||
return RecipeList(
|
if (_userInfo == null) {
|
||||||
recipes: snapshot.data!, homegroup: _userInfo.homegroup!);
|
return const Center(
|
||||||
|
child: Text("Could not load user, try logging in again..."),
|
||||||
|
);
|
||||||
|
} else if (_userInfo!.homegroup == null) {
|
||||||
|
return const Center(
|
||||||
|
child: Text("You must be in a homegroup to use this feature"),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return RecipeList(
|
||||||
|
recipes: snapshot.data!, homegroup: _userInfo!.homegroup!);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
@@ -63,6 +73,8 @@ class RecipeList extends StatefulWidget {
|
|||||||
|
|
||||||
class _RecipeListState extends State<RecipeList> {
|
class _RecipeListState extends State<RecipeList> {
|
||||||
int? _expandedCard;
|
int? _expandedCard;
|
||||||
|
late List<Recipe> _recipes;
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
|
||||||
void showError(String text) {
|
void showError(String text) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -78,16 +90,30 @@ class _RecipeListState extends State<RecipeList> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_scrollController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_recipes = widget.recipes;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
ListView.separated(
|
ListView.separated(
|
||||||
padding: const EdgeInsets.all(8),
|
controller: _scrollController,
|
||||||
itemCount: widget.recipes.length,
|
padding: const EdgeInsets.fromLTRB(
|
||||||
|
8, 8, 8, kFloatingActionButtonMargin + 48),
|
||||||
|
itemCount: _recipes.length,
|
||||||
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
||||||
itemBuilder: (context, index) => RecipeCard(
|
itemBuilder: (context, index) => RecipeCard(
|
||||||
recipe: widget.recipes[index],
|
recipe: _recipes[index],
|
||||||
isExpanded: _expandedCard == index,
|
isExpanded: _expandedCard == index,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -98,6 +124,29 @@ class _RecipeListState extends State<RecipeList> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onDismiss: () async {
|
||||||
|
if (_expandedCard != null && _expandedCard! > index) {
|
||||||
|
_expandedCard = _expandedCard! - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = await _recipes[index].delete();
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
showError("Permanent deletion of recipe failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_recipes.removeAt(index);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onChanged: () async {
|
||||||
|
Recipe? newRecipe = await Recipe.get(_recipes[index].id);
|
||||||
|
if (newRecipe != null) {
|
||||||
|
setState(() {
|
||||||
|
_recipes[index] = newRecipe;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
@@ -119,6 +168,16 @@ class _RecipeListState extends State<RecipeList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Recipe? created = await Recipe.create(name, widget.homegroup);
|
Recipe? created = await Recipe.create(name, widget.homegroup);
|
||||||
|
if (created != null) {
|
||||||
|
setState(() {
|
||||||
|
_recipes.insert(0, created);
|
||||||
|
_expandedCard = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
_scrollController.animateTo(0,
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.linear);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
label: Row(
|
label: Row(
|
||||||
children: const [Icon(Icons.note_add), Text("New Recipe")],
|
children: const [Icon(Icons.note_add), Text("New Recipe")],
|
||||||
|
|||||||
@@ -1,131 +1,282 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:one_trip/api/models/ingredient.dart';
|
import 'package:one_trip/api/models/recipeingredient.dart';
|
||||||
import 'package:one_trip/api/models/recipe.dart';
|
import 'package:one_trip/api/models/recipe.dart';
|
||||||
import 'package:one_trip/theme.dart';
|
import 'package:one_trip/theme.dart';
|
||||||
import 'package:one_trip/widgets/text_entry_dialog.dart';
|
import 'package:one_trip/widgets/text_entry_dialog.dart';
|
||||||
|
|
||||||
class RecipeCard extends StatelessWidget {
|
class RecipeCard extends StatefulWidget {
|
||||||
final Recipe recipe;
|
final Recipe recipe;
|
||||||
final bool isExpanded;
|
final bool isExpanded;
|
||||||
final Function() onTap;
|
final Function() onTap;
|
||||||
|
final Function() onDismiss;
|
||||||
|
final Function() onChanged;
|
||||||
const RecipeCard({
|
const RecipeCard({
|
||||||
super.key,
|
super.key,
|
||||||
required this.recipe,
|
required this.recipe,
|
||||||
required this.isExpanded,
|
required this.isExpanded,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
|
required this.onDismiss,
|
||||||
|
required this.onChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RecipeCard> createState() => _RecipeCardState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecipeCardState extends State<RecipeCard> with TickerProviderStateMixin {
|
||||||
|
double dismissAmount = 0.0;
|
||||||
|
bool willDismiss = false;
|
||||||
|
|
||||||
|
late final AnimationController _verticalController = AnimationController(
|
||||||
|
duration: const Duration(milliseconds: 500),
|
||||||
|
vsync: this,
|
||||||
|
);
|
||||||
|
late final Animation<double> _verticalAnimation = CurvedAnimation(
|
||||||
|
parent: _verticalController,
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
|
|
||||||
|
late final AnimationController _rotationController = AnimationController(
|
||||||
|
duration: const Duration(milliseconds: 500),
|
||||||
|
vsync: this,
|
||||||
|
upperBound: 0.5,
|
||||||
|
);
|
||||||
|
late final Animation<double> _rotationAnimation = CurvedAnimation(
|
||||||
|
parent: _rotationController,
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_verticalController.dispose();
|
||||||
|
_rotationController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant RecipeCard oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (!oldWidget.isExpanded && widget.isExpanded) {
|
||||||
|
_verticalController.forward();
|
||||||
|
_rotationController.forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldWidget.isExpanded && !widget.isExpanded) {
|
||||||
|
_verticalController.reverse();
|
||||||
|
_rotationController.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Material(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
color: Colors.transparent,
|
||||||
children: [
|
elevation: 10,
|
||||||
Card(
|
child: ClipRRect(
|
||||||
elevation: 10,
|
borderRadius: BorderRadius.circular(10),
|
||||||
shape: RoundedRectangleBorder(
|
child: Column(
|
||||||
borderRadius: BorderRadius.vertical(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
top: const Radius.circular(10),
|
children: [
|
||||||
bottom: isExpanded ? Radius.zero : const Radius.circular(10)),
|
Dismissible(
|
||||||
),
|
direction: widget.isExpanded
|
||||||
margin: EdgeInsets.zero,
|
? DismissDirection.none
|
||||||
child: GestureDetector(
|
: DismissDirection.endToStart,
|
||||||
onTap: onTap,
|
key: Key("${widget.recipe.id}"),
|
||||||
child: Column(
|
onDismissed: (direction) => widget.onDismiss(),
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
onUpdate: (details) {
|
||||||
children: [
|
setState(() {
|
||||||
Padding(
|
dismissAmount = details.progress;
|
||||||
padding: const EdgeInsets.all(8),
|
willDismiss = details.reached;
|
||||||
child: Row(
|
});
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
},
|
||||||
children: [
|
background: Container(
|
||||||
Expanded(
|
decoration: const BoxDecoration(
|
||||||
child: Text(
|
gradient: LinearGradient(
|
||||||
recipe.name,
|
begin: Alignment.centerLeft,
|
||||||
style: Theme.of(context).textTheme.headlineSmall,
|
end: Alignment.centerRight,
|
||||||
),
|
colors: [
|
||||||
),
|
Color.fromARGB(255, 255, 0, 0),
|
||||||
AnimatedRotation(
|
Color.fromARGB(255, 255, 170, 170),
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
turns: isExpanded ? 0.5 : 0,
|
|
||||||
child: const Icon(Icons.expand_more, size: 30),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
AnimatedSize(
|
child: Align(
|
||||||
duration: const Duration(milliseconds: 200),
|
alignment: Alignment.centerRight,
|
||||||
child: isExpanded
|
child: SizedBox(
|
||||||
? IngredientSection(ingredients: recipe.ingredients)
|
width: 45,
|
||||||
: const SizedBox(),
|
child: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
size: min(27.5 * dismissAmount + 20, 35),
|
||||||
|
color: willDismiss ? Colors.red : Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).cardColor,
|
||||||
|
margin: EdgeInsets.zero,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: widget.onTap,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.recipe.name,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
RotationTransition(
|
||||||
|
turns: _rotationAnimation,
|
||||||
|
child: const Icon(Icons.expand_more, size: 30))
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
SizeTransition(
|
||||||
|
sizeFactor: _verticalAnimation,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
IngredientSection(
|
||||||
|
ingredients: widget.recipe.ingredients,
|
||||||
|
onChanged: widget.onChanged,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: bottomButtonStyle.copyWith(
|
||||||
|
shape: const MaterialStatePropertyAll(
|
||||||
|
RoundedRectangleBorder())),
|
||||||
|
onPressed: () async {
|
||||||
|
String? name = await textEntryDialog(
|
||||||
|
context, "Ingredient Name", "Ingredient");
|
||||||
|
|
||||||
|
if (name == null || name == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RecipeIngredient? ingredient =
|
||||||
|
await RecipeIngredient.create(name, widget.recipe.id);
|
||||||
|
if (ingredient != null) {
|
||||||
|
widget.onChanged();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text("Add Ingredient"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
AnimatedSize(
|
),
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
child: isExpanded
|
|
||||||
? ElevatedButton(
|
|
||||||
style: bottomButtonStyle,
|
|
||||||
onPressed: () async {
|
|
||||||
String? name = await textEntryDialog(
|
|
||||||
context, "Ingredient Name", "Ingredient");
|
|
||||||
},
|
|
||||||
child: const Text("Add Ingredient"),
|
|
||||||
)
|
|
||||||
: const SizedBox(),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IngredientSection extends StatelessWidget {
|
class IngredientSection extends StatefulWidget {
|
||||||
final List<Ingredient> ingredients;
|
final List<RecipeIngredient> ingredients;
|
||||||
const IngredientSection({super.key, required this.ingredients});
|
final Function() onChanged;
|
||||||
|
const IngredientSection(
|
||||||
|
{super.key, required this.ingredients, required this.onChanged});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<IngredientSection> createState() => _IngredientSectionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _IngredientSectionState extends State<IngredientSection> {
|
||||||
|
double dismissAmount = 0.0;
|
||||||
|
bool willDismiss = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final TextStyle ingredientStyle = Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyLarge!
|
|
||||||
.copyWith(color: Theme.of(context).colorScheme.onSurface);
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
child: ListView.separated(
|
child: ListView.builder(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: widget.ingredients.isEmpty
|
||||||
itemCount: (ingredients.length / 2).ceil(),
|
? EdgeInsets.zero
|
||||||
|
: const EdgeInsets.all(8),
|
||||||
|
itemCount: widget.ingredients.length,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
separatorBuilder: (context, index) => Divider(
|
|
||||||
color: index % 2 == 0
|
|
||||||
? Theme.of(context).colorScheme.primary
|
|
||||||
: Theme.of(context).colorScheme.error,
|
|
||||||
),
|
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (ingredients.length % 2 == 0 ||
|
return Column(
|
||||||
index * 2 <= ingredients.length - 2) {
|
children: [
|
||||||
return Row(
|
Dismissible(
|
||||||
children: [
|
key: Key("${widget.ingredients[index].id}"),
|
||||||
Expanded(
|
direction: DismissDirection.endToStart,
|
||||||
child: Text(
|
background: Container(
|
||||||
ingredients[index * 2].name,
|
decoration: const BoxDecoration(
|
||||||
style: ingredientStyle,
|
gradient: LinearGradient(
|
||||||
|
begin: Alignment.centerLeft,
|
||||||
|
end: Alignment.centerRight,
|
||||||
|
colors: [
|
||||||
|
Color.fromARGB(255, 255, 0, 0),
|
||||||
|
Color.fromARGB(255, 255, 170, 170),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: SizedBox(
|
||||||
|
width: 40,
|
||||||
|
child: Icon(
|
||||||
|
Icons.delete,
|
||||||
|
size: min(27.5 * dismissAmount + 20, 35),
|
||||||
|
color: willDismiss ? Colors.red : Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
onUpdate: (details) {
|
||||||
child: Text(ingredients[index * 2 + 1].name,
|
setState(() {
|
||||||
style: ingredientStyle),
|
dismissAmount = details.progress;
|
||||||
)
|
willDismiss = details.reached;
|
||||||
],
|
});
|
||||||
);
|
},
|
||||||
} else {
|
onDismissed: (direction) async {
|
||||||
return Row(
|
bool success = await widget.ingredients[index].delete();
|
||||||
children: [
|
if (success) {
|
||||||
Text(ingredients[index * 2].name, style: ingredientStyle),
|
widget.onChanged();
|
||||||
],
|
}
|
||||||
);
|
},
|
||||||
}
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.ingredients[index].name,
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
)),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () async {
|
||||||
|
String? name = await textEntryDialog(
|
||||||
|
context, "Change Ingredient Name", "Ingredient",
|
||||||
|
defaultValue: widget.ingredients[index].name);
|
||||||
|
|
||||||
|
if (name == null || name == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RecipeIngredient? changed =
|
||||||
|
await widget.ingredients[index].patch(name);
|
||||||
|
if (changed != null) {
|
||||||
|
widget.onChanged();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.edit)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(
|
||||||
|
height: 1,
|
||||||
|
color: index % 2 == 0
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: Theme.of(context).colorScheme.error)
|
||||||
|
],
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -119,6 +119,15 @@ class ColorPage extends StatelessWidget {
|
|||||||
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
color: Theme.of(context).canvasColor,
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
"Canvas",
|
||||||
|
style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
|
||||||
|
)),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ class _LoginFormState extends State<LoginForm> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_usernameController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -294,6 +301,15 @@ class _SignupFormState extends State<SignupForm> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_usernameController.dispose();
|
||||||
|
_passwordController.dispose();
|
||||||
|
_firstnameController.dispose();
|
||||||
|
_lastnameController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Form(
|
return Form(
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ class _PaginationListViewState extends State<PaginationListView> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_scrollController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ class TextEntryForm extends StatefulWidget {
|
|||||||
class _TextEntryFormState extends State<TextEntryForm> {
|
class _TextEntryFormState extends State<TextEntryForm> {
|
||||||
late TextEditingController _textController;
|
late TextEditingController _textController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_textController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -36,7 +42,11 @@ class _TextEntryFormState extends State<TextEntryForm> {
|
|||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
autofocus: true,
|
||||||
controller: _textController,
|
controller: _textController,
|
||||||
|
onFieldSubmitted: (value) {
|
||||||
|
Navigator.pop(context, value);
|
||||||
|
},
|
||||||
decoration: InputDecoration(hintText: widget.label),
|
decoration: InputDecoration(hintText: widget.label),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
|||||||
@@ -1,68 +1,68 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"info": {
|
||||||
{
|
"version": 1,
|
||||||
"size" : "16x16",
|
"author": "xcode"
|
||||||
"idiom" : "mac",
|
|
||||||
"filename" : "app_icon_16.png",
|
|
||||||
"scale" : "1x"
|
|
||||||
},
|
},
|
||||||
{
|
"images": [
|
||||||
"size" : "16x16",
|
{
|
||||||
"idiom" : "mac",
|
"size": "16x16",
|
||||||
"filename" : "app_icon_32.png",
|
"idiom": "mac",
|
||||||
"scale" : "2x"
|
"filename": "app_icon_16.png",
|
||||||
},
|
"scale": "1x"
|
||||||
{
|
},
|
||||||
"size" : "32x32",
|
{
|
||||||
"idiom" : "mac",
|
"size": "16x16",
|
||||||
"filename" : "app_icon_32.png",
|
"idiom": "mac",
|
||||||
"scale" : "1x"
|
"filename": "app_icon_32.png",
|
||||||
},
|
"scale": "2x"
|
||||||
{
|
},
|
||||||
"size" : "32x32",
|
{
|
||||||
"idiom" : "mac",
|
"size": "32x32",
|
||||||
"filename" : "app_icon_64.png",
|
"idiom": "mac",
|
||||||
"scale" : "2x"
|
"filename": "app_icon_32.png",
|
||||||
},
|
"scale": "1x"
|
||||||
{
|
},
|
||||||
"size" : "128x128",
|
{
|
||||||
"idiom" : "mac",
|
"size": "32x32",
|
||||||
"filename" : "app_icon_128.png",
|
"idiom": "mac",
|
||||||
"scale" : "1x"
|
"filename": "app_icon_64.png",
|
||||||
},
|
"scale": "2x"
|
||||||
{
|
},
|
||||||
"size" : "128x128",
|
{
|
||||||
"idiom" : "mac",
|
"size": "128x128",
|
||||||
"filename" : "app_icon_256.png",
|
"idiom": "mac",
|
||||||
"scale" : "2x"
|
"filename": "app_icon_128.png",
|
||||||
},
|
"scale": "1x"
|
||||||
{
|
},
|
||||||
"size" : "256x256",
|
{
|
||||||
"idiom" : "mac",
|
"size": "128x128",
|
||||||
"filename" : "app_icon_256.png",
|
"idiom": "mac",
|
||||||
"scale" : "1x"
|
"filename": "app_icon_256.png",
|
||||||
},
|
"scale": "2x"
|
||||||
{
|
},
|
||||||
"size" : "256x256",
|
{
|
||||||
"idiom" : "mac",
|
"size": "256x256",
|
||||||
"filename" : "app_icon_512.png",
|
"idiom": "mac",
|
||||||
"scale" : "2x"
|
"filename": "app_icon_256.png",
|
||||||
},
|
"scale": "1x"
|
||||||
{
|
},
|
||||||
"size" : "512x512",
|
{
|
||||||
"idiom" : "mac",
|
"size": "256x256",
|
||||||
"filename" : "app_icon_512.png",
|
"idiom": "mac",
|
||||||
"scale" : "1x"
|
"filename": "app_icon_512.png",
|
||||||
},
|
"scale": "2x"
|
||||||
{
|
},
|
||||||
"size" : "512x512",
|
{
|
||||||
"idiom" : "mac",
|
"size": "512x512",
|
||||||
"filename" : "app_icon_1024.png",
|
"idiom": "mac",
|
||||||
"scale" : "2x"
|
"filename": "app_icon_512.png",
|
||||||
}
|
"scale": "1x"
|
||||||
],
|
},
|
||||||
"info" : {
|
{
|
||||||
"version" : 1,
|
"size": "512x512",
|
||||||
"author" : "xcode"
|
"idiom": "mac",
|
||||||
}
|
"filename": "app_icon_1024.png",
|
||||||
|
"scale": "2x"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 9.6 KiB |
|
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 780 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 4.8 KiB |
@@ -110,3 +110,6 @@ flutter_icons:
|
|||||||
macos:
|
macos:
|
||||||
generate: true
|
generate: true
|
||||||
image_path: "assets/icons/desktop.png"
|
image_path: "assets/icons/desktop.png"
|
||||||
|
web:
|
||||||
|
generate: true
|
||||||
|
image_path: "assets/icons/desktop.png"
|
||||||
|
Before Width: | Height: | Size: 917 B After Width: | Height: | Size: 780 B |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 40 KiB |
@@ -14,7 +14,7 @@
|
|||||||
This is a placeholder for base href that will be replaced by the value of
|
This is a placeholder for base href that will be replaced by the value of
|
||||||
the `--base-href` argument provided to `flutter build`.
|
the `--base-href` argument provided to `flutter build`.
|
||||||
-->
|
-->
|
||||||
<base href="$FLUTTER_BASE_HREF">
|
<base href="/app/">
|
||||||
|
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 19 KiB |
@@ -6,8 +6,16 @@ import nested_admin
|
|||||||
from api.models import *
|
from api.models import *
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
class IngredientInline(nested_admin.NestedGenericTabularInline):
|
# class IngredientInline(nested_admin.NestedGenericTabularInline):
|
||||||
model = Ingredient
|
# model = Ingredient
|
||||||
|
# extra = 0
|
||||||
|
|
||||||
|
class RecipeIngredientInline(nested_admin.NestedTabularInline):
|
||||||
|
model = RecipeIngredient
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
class ListIngredientInline(nested_admin.NestedTabularInline):
|
||||||
|
model = ListIngredient
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
class UserInline(nested_admin.NestedTabularInline):
|
class UserInline(nested_admin.NestedTabularInline):
|
||||||
@@ -28,20 +36,20 @@ class HomegroupInviteInline(nested_admin.NestedTabularInline):
|
|||||||
|
|
||||||
class RecipeInline(nested_admin.NestedTabularInline):
|
class RecipeInline(nested_admin.NestedTabularInline):
|
||||||
model = Recipe
|
model = Recipe
|
||||||
inlines = (IngredientInline,)
|
inlines = (RecipeIngredientInline,)
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
@admin.register(Recipe)
|
@admin.register(Recipe)
|
||||||
class RecipeAdmin(nested_admin.NestedModelAdmin):
|
class RecipeAdmin(nested_admin.NestedModelAdmin):
|
||||||
list_display = ("name",)
|
list_display = ("name",)
|
||||||
inlines = (IngredientInline,)
|
inlines = (RecipeIngredientInline,)
|
||||||
|
|
||||||
@admin.register(Homegroup)
|
@admin.register(Homegroup)
|
||||||
class HomegroupAdmin(nested_admin.NestedModelAdmin):
|
class HomegroupAdmin(nested_admin.NestedModelAdmin):
|
||||||
list_display = ("id", "name")
|
list_display = ("id", "name")
|
||||||
inlines = (UserInline, HomegroupInviteInline, RecipeInline, IngredientInline)
|
inlines = (UserInline, HomegroupInviteInline, RecipeInline,)
|
||||||
|
|
||||||
@admin.register(List)
|
@admin.register(List)
|
||||||
class ListAdmin(nested_admin.NestedModelAdmin):
|
class ListAdmin(nested_admin.NestedModelAdmin):
|
||||||
list_display = ("homegroup",)
|
list_display = ("homegroup",)
|
||||||
inlines = (RecipeInline, IngredientInline)
|
inlines = (ListIngredientInline,)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Generated by Django 4.1.3 on 2022-11-27 21:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0002_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RecipeIngredient',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=50)),
|
||||||
|
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='api.recipe')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ListIngredient',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=50)),
|
||||||
|
('in_cart', models.BooleanField(default=False)),
|
||||||
|
('list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='api.list')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 4.1.3 on 2022-11-27 22:00
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0003_recipeingredient_listingredient'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='recipe',
|
||||||
|
name='list',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Ingredient',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -3,15 +3,6 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class Ingredient(models.Model):
|
|
||||||
limit = models.Q(app_label="api", model="recipe") | models.Q(app_label="api", model="list")
|
|
||||||
content_type = models.ForeignKey(ContentType, limit_choices_to=limit, on_delete=models.CASCADE)
|
|
||||||
object_id = models.PositiveBigIntegerField()
|
|
||||||
content_object = GenericForeignKey()
|
|
||||||
|
|
||||||
|
|
||||||
name = models.CharField(max_length=50)
|
|
||||||
in_stock = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
class HomegroupInvite(models.Model):
|
class HomegroupInvite(models.Model):
|
||||||
homegroup = models.ForeignKey("api.Homegroup", on_delete=models.CASCADE, related_name="invites", blank=True)
|
homegroup = models.ForeignKey("api.Homegroup", on_delete=models.CASCADE, related_name="invites", blank=True)
|
||||||
@@ -33,15 +24,21 @@ class Homegroup(models.Model):
|
|||||||
return f"{self.id}: {self.name}"
|
return f"{self.id}: {self.name}"
|
||||||
|
|
||||||
class List(models.Model):
|
class List(models.Model):
|
||||||
# Foreign Key Recipe -> List [as recipes]
|
# Foreign Key ListIngredient -> List [as ingredients]
|
||||||
extra_ingredients = GenericRelation(Ingredient, related_query_name="extra_ingredients")
|
|
||||||
homegroup = models.OneToOneField(Homegroup, on_delete=models.CASCADE, primary_key=True)
|
homegroup = models.OneToOneField(Homegroup, on_delete=models.CASCADE, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
class Recipe(models.Model):
|
class Recipe(models.Model):
|
||||||
|
# Foreign Key RecipeIngredient -> List [as ingredients]
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
homegroup = models.ForeignKey(Homegroup, related_name="recipes", on_delete=models.CASCADE)
|
homegroup = models.ForeignKey(Homegroup, related_name="recipes", on_delete=models.CASCADE)
|
||||||
list = models.ForeignKey(List, related_name="recipes", on_delete=models.SET_NULL, blank=True, null=True)
|
|
||||||
ingredients = GenericRelation(Ingredient, related_query_name="ingredients")
|
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeIngredient(models.Model):
|
||||||
|
name = models.CharField(max_length=50)
|
||||||
|
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE, related_name="ingredients")
|
||||||
|
|
||||||
|
class ListIngredient(models.Model):
|
||||||
|
name = models.CharField(max_length=50)
|
||||||
|
list = models.ForeignKey(List, on_delete=models.CASCADE, related_name="ingredients")
|
||||||
|
in_cart = models.BooleanField(default=False)
|
||||||
@@ -2,11 +2,15 @@ from rest_framework import serializers
|
|||||||
from api.models import *
|
from api.models import *
|
||||||
from users.serializers import UserSerializer
|
from users.serializers import UserSerializer
|
||||||
|
|
||||||
class IngredientSerializer(serializers.ModelSerializer):
|
class RecipeIngredientSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Ingredient
|
model = RecipeIngredient
|
||||||
fields = ["id", "name", "in_stock", "content_type", "object_id"]
|
fields = ["id", "name", "recipe"]
|
||||||
read_only_fields = ["id"]
|
|
||||||
|
class ListIngredientSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ListIngredient
|
||||||
|
fields = ["id", "name", "list", "in_cart"]
|
||||||
|
|
||||||
class RecipeSerializer(serializers.ModelSerializer):
|
class RecipeSerializer(serializers.ModelSerializer):
|
||||||
ingredients = serializers.SerializerMethodField()
|
ingredients = serializers.SerializerMethodField()
|
||||||
@@ -18,7 +22,20 @@ class RecipeSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_ingredients(self, instance):
|
def get_ingredients(self, instance):
|
||||||
ingredients = instance.ingredients.all().order_by("name")
|
ingredients = instance.ingredients.all().order_by("name")
|
||||||
return IngredientSerializer(ingredients, many=True).data
|
return RecipeIngredientSerializer(ingredients, many=True).data
|
||||||
|
|
||||||
|
class ListSerializer(serializers.ModelSerializer):
|
||||||
|
ingredients = serializers.SerializerMethodField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = List
|
||||||
|
fields = ["homegroup", "ingredients"]
|
||||||
|
read_only_fields = ["homegroup"]
|
||||||
|
|
||||||
|
def get_ingredients(self, instance):
|
||||||
|
ingredients = instance.ingredients.all().order_by("name")
|
||||||
|
return ListIngredientSerializer(ingredients, many=True).data
|
||||||
|
|
||||||
|
|
||||||
class HomegroupSerializer(serializers.ModelSerializer):
|
class HomegroupSerializer(serializers.ModelSerializer):
|
||||||
users = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
users = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ from api import views
|
|||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'recipes', views.RecipeView)
|
router.register(r'recipes', views.RecipeView)
|
||||||
router.register(r'ingredients', views.IngredientView)
|
router.register(r'lists', views.ListView)
|
||||||
|
router.register(r'recipeingredients', views.RecipeIngredientView)
|
||||||
|
router.register(r'listingredients', views.ListIngredientView)
|
||||||
router.register(r'homegroups', views.HomegroupView)
|
router.register(r'homegroups', views.HomegroupView)
|
||||||
router.register(r'groupinvites', views.HomegroupInviteView)
|
router.register(r'groupinvites', views.HomegroupInviteView)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls))
|
path('', include(router.urls)),
|
||||||
|
# path('ingredienttypes/', views.IngredientContentTypesView.as_view())
|
||||||
]
|
]
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from rest_framework import viewsets
|
from rest_framework import viewsets, mixins, views, status, permissions
|
||||||
|
from rest_framework.response import Response
|
||||||
from api.serializers import *
|
from api.serializers import *
|
||||||
from api.models import *
|
from api.models import *
|
||||||
|
|
||||||
@@ -7,10 +7,6 @@ class RecipeView(viewsets.ModelViewSet):
|
|||||||
serializer_class = RecipeSerializer
|
serializer_class = RecipeSerializer
|
||||||
queryset = Recipe.objects.all()
|
queryset = Recipe.objects.all()
|
||||||
|
|
||||||
class IngredientView(viewsets.ModelViewSet):
|
|
||||||
serializer_class = IngredientSerializer
|
|
||||||
queryset = Ingredient.objects.all()
|
|
||||||
|
|
||||||
class HomegroupView(viewsets.ModelViewSet):
|
class HomegroupView(viewsets.ModelViewSet):
|
||||||
serializer_class = HomegroupSerializer
|
serializer_class = HomegroupSerializer
|
||||||
queryset = Homegroup.objects.all()
|
queryset = Homegroup.objects.all()
|
||||||
@@ -18,3 +14,15 @@ class HomegroupView(viewsets.ModelViewSet):
|
|||||||
class HomegroupInviteView(viewsets.ModelViewSet):
|
class HomegroupInviteView(viewsets.ModelViewSet):
|
||||||
serializer_class = InviteSerializer
|
serializer_class = InviteSerializer
|
||||||
queryset = HomegroupInvite.objects.all()
|
queryset = HomegroupInvite.objects.all()
|
||||||
|
|
||||||
|
class RecipeIngredientView(viewsets.ModelViewSet):
|
||||||
|
serializer_class = RecipeIngredientSerializer
|
||||||
|
queryset = RecipeIngredient.objects.all()
|
||||||
|
|
||||||
|
class ListIngredientView(viewsets.ModelViewSet):
|
||||||
|
serializer_class = ListIngredientSerializer
|
||||||
|
queryset = ListIngredient.objects.all()
|
||||||
|
|
||||||
|
class ListView(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
|
||||||
|
serializer_class = ListSerializer
|
||||||
|
queryset = List.objects.all()
|
||||||
18
one_trip_api/gunicorn.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=gunicorn daemon
|
||||||
|
Requires=gunicorn.socket
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=django
|
||||||
|
Group=www-data
|
||||||
|
Environment="DJANGO_RELEASE=True"
|
||||||
|
WorkingDirectory=/opt/django/OneTrip/one_trip_api
|
||||||
|
ExecStart=/opt/django/OneTrip/one_trip_api/venv/bin/gunicorn \
|
||||||
|
--access-logfile - \
|
||||||
|
--workers 3 \
|
||||||
|
--bind unix:/run/gunicorn.sock \
|
||||||
|
one_trip_api.wsgi:application
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
8
one_trip_api/gunicorn.socket
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=gunicorn socket
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=/run/gunicorn.sock
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sockets.target
|
||||||
@@ -13,7 +13,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
MEDIA_URL = "/media/"
|
MEDIA_URL = "/media/"
|
||||||
|
|
||||||
@@ -24,7 +24,8 @@ REST_FRAMEWORK = {
|
|||||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
'rest_framework.authentication.TokenAuthentication',
|
'rest_framework.authentication.TokenAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
]
|
],
|
||||||
|
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
|
||||||
}
|
}
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|||||||