From 9ba9341afa96827625a4f5504172a4b5cdae8070 Mon Sep 17 00:00:00 2001 From: Ahmadreza Zibaei Date: Mon, 1 Oct 2018 19:40:18 +0330 Subject: [PATCH] implement category selector --- lib/main.dart | 11 ++++++++++- lib/models/Series.dart | 12 ++++++++++++ lib/pages/categories.dart | 2 +- lib/pages/series.dart | 25 +++++++++++++++++-------- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d1ad30b..586ef60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -62,7 +62,7 @@ class CantonFair extends StatelessWidget { '/phases/:phase', handler: Handler(handlerFunc: (BuildContext context, Map> params) { - return new SeriesRoute.byPhase( + return new SeriesRoute( phase: params['phase'][0], ); }), @@ -74,6 +74,15 @@ class CantonFair extends StatelessWidget { return new CategoriesRoute(); }), ); + router.define( + '/categories/:category_uuid', + handler: Handler(handlerFunc: + (BuildContext context, Map> params) { + return new SeriesRoute( + category: params['category_uuid'][0], + ); + }), + ); router.define( '/settings', handler: Handler(handlerFunc: diff --git a/lib/models/Series.dart b/lib/models/Series.dart index 9138987..d94c931 100644 --- a/lib/models/Series.dart +++ b/lib/models/Series.dart @@ -97,6 +97,18 @@ class Series { } if (series.length > 0) return series[0]; return null; + } + + static Future> getSeriesByCategory(String category) async { + var result = await db + .rawQuery('SELECT * FROM $tableName WHERE $dbCategoryUUID = "$category";'); + List series = []; + for (Map item in result) { + Series s = new Series.fromMap(item); + await s.fetchCount(); + series.add(s); + } + return series; } static Future> getSeriesByPhase(phase) async { diff --git a/lib/pages/categories.dart b/lib/pages/categories.dart index ac72744..1e8a93f 100644 --- a/lib/pages/categories.dart +++ b/lib/pages/categories.dart @@ -70,7 +70,7 @@ class _CategoriesRoute extends State { } void _categoryPressed(Category category) { - print("Category ${category.name} pressed !"); + Application.router.navigateTo(context, "/categories/${category.uuid}"); } @override diff --git a/lib/pages/series.dart b/lib/pages/series.dart index 6e2ffde..562582c 100644 --- a/lib/pages/series.dart +++ b/lib/pages/series.dart @@ -7,24 +7,25 @@ import '../utils/ui.dart'; class SeriesRoute extends StatefulWidget { final String phase; + final String category; - SeriesRoute({this.phase}); - - SeriesRoute.byPhase({this.phase}); + SeriesRoute({this.phase, this.category}); @override - _SeriesRoute createState() => new _SeriesRoute(phase: phase); + _SeriesRoute createState() => + new _SeriesRoute(phase: phase, category: category); } class _SeriesRoute extends State with SingleTickerProviderStateMixin { final String phase; + final String category; List list = new List(); List displayList = new List(); bool _ready = false; - _SeriesRoute({this.phase}); + _SeriesRoute({this.phase, this.category}); @override Widget build(BuildContext context) { @@ -79,8 +80,16 @@ class _SeriesRoute extends State @override void initState() { super.initState(); - if (phase == null) { - Series.getSeries().then((result) { + if (phase != null) { + Series.getSeriesByPhase(phase).then((result) { + setState(() { + list = result; + displayList = list; + _ready = true; + }); + }); + } else if (category != null) { + Series.getSeriesByCategory(category).then((result) { setState(() { list = result; displayList = list; @@ -88,7 +97,7 @@ class _SeriesRoute extends State }); }); } else { - Series.getSeriesByPhase(phase).then((result) { + Series.getSeries().then((result) { setState(() { list = result; displayList = list;