add websock functionality

This commit is contained in:
Alexander Laevens
2022-11-30 02:52:56 -07:00
parent 34edcd53cb
commit 339b0c6ad9
41 changed files with 1028 additions and 189 deletions

View File

@@ -23,7 +23,7 @@ class _RecipesPageState extends State<RecipesPage> {
return [];
}
List<Recipe> recipes = await Recipe.getList(userInfo.homegroup!);
List<Recipe> recipes = await Recipe.getList();
return recipes;
}
@@ -106,47 +106,44 @@ class _RecipeListState extends State<RecipeList> {
Widget build(BuildContext context) {
return Stack(
children: [
ListView.separated(
Scrollbar(
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(
8, 8, 8, kFloatingActionButtonMargin + 48),
itemCount: _recipes.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) => RecipeCard(
recipe: _recipes[index],
isExpanded: _expandedCard == index,
onTap: () {
setState(() {
if (_expandedCard == index) {
_expandedCard = null;
} else {
_expandedCard = index;
}
});
},
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) {
child: ListView.separated(
controller: _scrollController,
padding: const EdgeInsets.fromLTRB(
8, 8, 8, kFloatingActionButtonMargin + 48),
itemCount: _recipes.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) => RecipeCard(
recipe: _recipes[index],
isExpanded: _expandedCard == index,
onTap: () {
setState(() {
_recipes[index] = newRecipe;
if (_expandedCard == index) {
_expandedCard = null;
} else {
_expandedCard = index;
}
});
}
},
},
onDismiss: () {
if (_expandedCard != null && _expandedCard! > index) {
_expandedCard = _expandedCard! - 1;
}
setState(() {
_recipes.removeAt(index);
});
},
onChanged: () async {
Recipe? newRecipe = await Recipe.get(_recipes[index].id);
if (newRecipe != null) {
setState(() {
_recipes[index] = newRecipe;
});
}
},
),
),
),
Align(
@@ -154,6 +151,7 @@ class _RecipeListState extends State<RecipeList> {
child: Padding(
padding: const EdgeInsets.all(8.0),
child: FloatingActionButton.extended(
heroTag: "add-ingredient",
onPressed: () async {
String? name =
await textEntryDialog(context, "Recipe Name", "Recipe");
@@ -180,11 +178,11 @@ class _RecipeListState extends State<RecipeList> {
}
},
label: Row(
children: const [Icon(Icons.note_add), Text("New Recipe")],
children: const [Icon(Icons.post_add), Text("Recipe")],
),
),
),
)
),
],
);
}

View File

@@ -85,6 +85,7 @@ class _RecipeCardState extends State<RecipeCard> with TickerProviderStateMixin {
: DismissDirection.endToStart,
key: Key("${widget.recipe.id}"),
onDismissed: (direction) => widget.onDismiss(),
confirmDismiss: (direction) => widget.recipe.delete(),
onUpdate: (details) {
setState(() {
dismissAmount = details.progress;
@@ -92,16 +93,8 @@ class _RecipeCardState extends State<RecipeCard> with TickerProviderStateMixin {
});
},
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromARGB(255, 255, 0, 0),
Color.fromARGB(255, 255, 170, 170),
],
),
),
color: Color.lerp(Colors.transparent, Colors.red,
min(dismissAmount * 2.5, 1)),
child: Align(
alignment: Alignment.centerRight,
child: SizedBox(
@@ -109,7 +102,7 @@ class _RecipeCardState extends State<RecipeCard> with TickerProviderStateMixin {
child: Icon(
Icons.delete,
size: min(27.5 * dismissAmount + 20, 35),
color: willDismiss ? Colors.red : Colors.white,
color: Colors.white,
),
),
),
@@ -193,9 +186,11 @@ class _IngredientSectionState extends State<IngredientSection> {
@override
Widget build(BuildContext context) {
return Container(
return Material(
elevation: 10,
color: Theme.of(context).colorScheme.surface,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
padding: widget.ingredients.isEmpty
? EdgeInsets.zero
: const EdgeInsets.all(8),
@@ -208,16 +203,8 @@ class _IngredientSectionState extends State<IngredientSection> {
key: Key("${widget.ingredients[index].id}"),
direction: DismissDirection.endToStart,
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromARGB(255, 255, 0, 0),
Color.fromARGB(255, 255, 170, 170),
],
),
),
color: Color.lerp(Colors.transparent, Colors.red,
min(dismissAmount * 2.5, 1)),
child: Align(
alignment: Alignment.centerRight,
child: SizedBox(
@@ -225,7 +212,7 @@ class _IngredientSectionState extends State<IngredientSection> {
child: Icon(
Icons.delete,
size: min(27.5 * dismissAmount + 20, 35),
color: willDismiss ? Colors.red : Colors.white,
color: Colors.white,
),
),
),
@@ -236,11 +223,10 @@ class _IngredientSectionState extends State<IngredientSection> {
willDismiss = details.reached;
});
},
confirmDismiss: (direction) async =>
await widget.ingredients[index].delete(),
onDismissed: (direction) async {
bool success = await widget.ingredients[index].delete();
if (success) {
widget.onChanged();
}
widget.onChanged();
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
@@ -251,22 +237,23 @@ class _IngredientSectionState extends State<IngredientSection> {
style: Theme.of(context).textTheme.titleMedium,
)),
IconButton(
onPressed: () async {
String? name = await textEntryDialog(
context, "Change Ingredient Name", "Ingredient",
defaultValue: widget.ingredients[index].name);
onPressed: () async {
String? name = await textEntryDialog(
context, "Change Ingredient Name", "Ingredient",
defaultValue: widget.ingredients[index].name);
if (name == null || name == "") {
return;
}
if (name == null || name == "") {
return;
}
RecipeIngredient? changed =
await widget.ingredients[index].patch(name);
if (changed != null) {
widget.onChanged();
}
},
icon: const Icon(Icons.edit)),
RecipeIngredient? changed =
await widget.ingredients[index].patch(name);
if (changed != null) {
widget.onChanged();
}
},
icon: const Icon(Icons.edit),
),
],
),
),