Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Teifun2 committed Aug 2, 2020
2 parents b7a04e2 + 640c152 commit e524d15
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 31 deletions.
68 changes: 38 additions & 30 deletions lib/src/screens/landing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:nextcloud_cookbook_flutter/src/blocs/authentication/authenticati
import 'package:nextcloud_cookbook_flutter/src/blocs/categories/categories.dart';
import 'package:nextcloud_cookbook_flutter/src/models/category.dart';
import 'package:nextcloud_cookbook_flutter/src/screens/recipes_list_screen.dart';
import 'package:nextcloud_cookbook_flutter/src/screens/search_screen.dart';
import 'package:nextcloud_cookbook_flutter/src/widget/category_card.dart';

class LandingScreen extends StatefulWidget {
Expand All @@ -20,6 +21,22 @@ class _LandingScreenState extends State<LandingScreen> {
appBar: AppBar(
title: Text("Cookbook"),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.search,
semanticLabel: 'Search',
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return SearchScreen();
},
),
);
},
),
IconButton(
icon: Icon(
Icons.refresh,
Expand Down Expand Up @@ -63,36 +80,27 @@ class _LandingScreenState extends State<LandingScreen> {
Widget _buildCategoriesScreen(List<Category> categories) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
TextField(
readOnly: true,
),
Expanded(
child: GridView.count(
crossAxisCount: 3,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
padding: EdgeInsets.only(top: 10),
semanticChildCount: categories.length,
children: categories
.map(
(category) => GestureDetector(
child: CategoryCard(category),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return RecipesListScreen(category: category.name);
},
),
),
),
)
.toList(),
),
),
],
child: GridView.count(
crossAxisCount: 3,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
padding: EdgeInsets.only(top: 10),
semanticChildCount: categories.length,
children: categories
.map(
(category) => GestureDetector(
child: CategoryCard(category),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return RecipesListScreen(category: category.name);
},
),
),
),
)
.toList(),
),
);
}
Expand Down
46 changes: 46 additions & 0 deletions lib/src/screens/search_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flutter/material.dart';
import 'package:nextcloud_cookbook_flutter/src/models/recipe_short.dart';
import 'package:nextcloud_cookbook_flutter/src/screens/recipe_screen.dart';
import 'package:nextcloud_cookbook_flutter/src/services/data_repository.dart';
import 'package:nextcloud_cookbook_flutter/src/widget/authentication_cached_network_image.dart';

class SearchScreen extends StatelessWidget {
SearchScreen() {
DataRepository().fetchSearchRecipes();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Search"),
),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: SearchBar<RecipeShort>(
minimumChars: 3,
mainAxisSpacing: 5,
onCancelled: () => Navigator.pop(context),
onSearch: (text) => DataRepository().searchRecipes(text),
onItemFound: (RecipeShort item, int index) {
return ListTile(
title: Text(item.name),
trailing: Container(
child:
AuthenticationCachedNetworkImage(imagePath: item.imageUrl),
),
onTap: () => Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => RecipeScreen(recipeShort: item),
)),
);
},
onError: (error) => Text(error.toString()),
emptyWidget: Center(child: Text("No recipe found!")),
),
),
);
}
}
14 changes: 14 additions & 0 deletions lib/src/services/data_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class DataRepository {
RecipeProvider recipeProvider = RecipeProvider();
CategoriesProvider categoriesProvider = CategoriesProvider();

// Data
static Future<List<RecipeShort>> _allRecipesShort;

// Actions
Future<List<RecipeShort>> fetchRecipesShort({String category = 'all'}) {
if (category == 'all') {
Expand Down Expand Up @@ -52,4 +55,15 @@ class DataRepository {

return category;
}

Future<void> fetchSearchRecipes() async {
_allRecipesShort = fetchRecipesShort(category: "all");
}

Future<List<RecipeShort>> searchRecipes(String pattern) async {
return (await _allRecipesShort)
.where((element) =>
element.name.toLowerCase().contains(pattern.toLowerCase()))
.toList();
}
}
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A new Flutter application.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.2.2+5
version: 0.3.0+6

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down Expand Up @@ -39,6 +39,9 @@ dependencies:
# For easier handling without hand built hash comparison
equatable: ^1.0.0

# Search
flappy_search_bar: ^1.7.2

cached_network_image: 2.1.0+1

flutter_spinkit: "^2.1.0"
Expand Down

0 comments on commit e524d15

Please sign in to comment.