You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meals/lib/screens/filters.dart

135 lines
4.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:meals/screens/tabs.dart';
import 'package:meals/widgets/main_drawer.dart';
enum Filter {
glutenFree,
lactoseFree,
veggie,
vegan,
}
class FiltersScreen extends StatefulWidget {
final Map<Filter, bool> currentFilters;
const FiltersScreen({Key? key, required this.currentFilters})
: super(key: key);
@override
State<FiltersScreen> createState() => _FiltersScreenState();
}
class _FiltersScreenState extends State<FiltersScreen> {
bool _glutenFreeFilterSet = false;
bool _lactoseFreeFilterSet = false;
bool _veggieFilterSet = false;
bool _veganFilterSet = false;
@override
void initState() {
super.initState();
setState(() {
_glutenFreeFilterSet = widget.currentFilters[Filter.glutenFree]!;
_lactoseFreeFilterSet = widget.currentFilters[Filter.lactoseFree]!;
_veggieFilterSet = widget.currentFilters[Filter.veggie]!;
_veganFilterSet = widget.currentFilters[Filter.vegan]!;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Your filters'),
),
body: WillPopScope(
onWillPop: () async {
Navigator.of(context).pop({
Filter.glutenFree: _glutenFreeFilterSet,
Filter.lactoseFree: _lactoseFreeFilterSet,
Filter.veggie: _veggieFilterSet,
Filter.vegan: _veganFilterSet,
});
return false;
},
child: Column(
children: [
SwitchListTile(
value: _glutenFreeFilterSet,
onChanged: (checked) => setState(() {
_glutenFreeFilterSet = checked;
}),
title: Text(
'Gluten free',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
subtitle: Text(
'Only includes gluten-free meals',
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
activeColor: Theme.of(context).colorScheme.tertiary,
contentPadding: const EdgeInsets.only(left: 34, right: 22),
),
SwitchListTile(
value: _lactoseFreeFilterSet,
onChanged: (checked) => setState(() {
_lactoseFreeFilterSet = checked;
}),
title: Text(
'Lactose free',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
subtitle: Text(
'Only includes lactose-free meals',
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
activeColor: Theme.of(context).colorScheme.tertiary,
contentPadding: const EdgeInsets.only(left: 34, right: 22),
),
SwitchListTile(
value: _veggieFilterSet,
onChanged: (checked) => setState(() {
_veggieFilterSet = checked;
}),
title: Text(
'Veggie',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
subtitle: Text(
'Only includes veggie meals',
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
activeColor: Theme.of(context).colorScheme.tertiary,
contentPadding: const EdgeInsets.only(left: 34, right: 22),
),
SwitchListTile(
value: _veganFilterSet,
onChanged: (checked) => setState(() {
_veganFilterSet = checked;
}),
title: Text(
'Vegan',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
subtitle: Text(
'Only includes vegan meals',
style: Theme.of(context).textTheme.labelMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground),
),
activeColor: Theme.of(context).colorScheme.tertiary,
contentPadding: const EdgeInsets.only(left: 34, right: 22),
)
],
),
));
}
}