Skip to content

Commit

Permalink
implement category selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdrz committed Oct 1, 2018
1 parent a521d62 commit 9ba9341
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
11 changes: 10 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CantonFair extends StatelessWidget {
'/phases/:phase',
handler: Handler(handlerFunc:
(BuildContext context, Map<String, List<String>> params) {
return new SeriesRoute.byPhase(
return new SeriesRoute(
phase: params['phase'][0],
);
}),
Expand All @@ -74,6 +74,15 @@ class CantonFair extends StatelessWidget {
return new CategoriesRoute();
}),
);
router.define(
'/categories/:category_uuid',
handler: Handler(handlerFunc:
(BuildContext context, Map<String, List<String>> params) {
return new SeriesRoute(
category: params['category_uuid'][0],
);
}),
);
router.define(
'/settings',
handler: Handler(handlerFunc:
Expand Down
12 changes: 12 additions & 0 deletions lib/models/Series.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ class Series {
}
if (series.length > 0) return series[0];
return null;
}

static Future<List<Series>> getSeriesByCategory(String category) async {
var result = await db
.rawQuery('SELECT * FROM $tableName WHERE $dbCategoryUUID = "$category";');
List<Series> series = [];
for (Map<String, dynamic> item in result) {
Series s = new Series.fromMap(item);
await s.fetchCount();
series.add(s);
}
return series;
}

static Future<List<Series>> getSeriesByPhase(phase) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _CategoriesRoute extends State<CategoriesRoute> {
}

void _categoryPressed(Category category) {
print("Category ${category.name} pressed !");
Application.router.navigateTo(context, "/categories/${category.uuid}");
}

@override
Expand Down
25 changes: 17 additions & 8 deletions lib/pages/series.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SeriesRoute>
with SingleTickerProviderStateMixin {
final String phase;
final String category;

List<Series> list = new List<Series>();
List<Series> displayList = new List<Series>();
bool _ready = false;

_SeriesRoute({this.phase});
_SeriesRoute({this.phase, this.category});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -79,16 +80,24 @@ class _SeriesRoute extends State<SeriesRoute>
@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;
_ready = true;
});
});
} else {
Series.getSeriesByPhase(phase).then((result) {
Series.getSeries().then((result) {
setState(() {
list = result;
displayList = list;
Expand Down

0 comments on commit 9ba9341

Please sign in to comment.