Skip to content

Commit

Permalink
Merge pull request #64 from enrique-lozano/hot-fixes
Browse files Browse the repository at this point in the history
Category selector modal background
  • Loading branch information
enrique-lozano authored Oct 24, 2023
2 parents 833e644 + 59baddc commit bf20f91
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 233 deletions.
248 changes: 139 additions & 109 deletions lib/app/categories/categories_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:monekin/core/database/services/category/category_service.dart';
import 'package:monekin/core/models/category/category.dart';
import 'package:monekin/core/presentation/widgets/bottomSheetFooter.dart';
import 'package:monekin/core/presentation/widgets/persistent_footer_button.dart';
import 'package:monekin/core/presentation/widgets/scrollable_with_bottom_gradient.dart';
import 'package:monekin/core/utils/color_utils.dart';
import 'package:monekin/i18n/translations.g.dart';

Expand All @@ -21,20 +22,15 @@ Future<List<Category>?> showCategoryListModal(
return showModalBottomSheet<List<Category>>(
context: context,
isScrollControlled: true,
showDragHandle: false,
backgroundColor:
Theme.of(context).appBarTheme.backgroundColor!.darken(0.02),
showDragHandle: true,
builder: (context) {
return DraggableScrollableSheet(
expand: false,
maxChildSize: 0.85,
minChildSize: 0.85,
initialChildSize: 0.85,
builder: (context, scrollController) {
return Padding(
padding: const EdgeInsets.only(top: 5),
child: page,
);
return page;
});
},
);
Expand Down Expand Up @@ -75,6 +71,7 @@ class _CategoriesListState extends State<CategoriesList> {

return ListView.builder(
itemCount: categoriesToDisplay.length,
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
itemBuilder: (context, index) {
final category = categoriesToDisplay[index];

Expand Down Expand Up @@ -162,120 +159,153 @@ class _CategoriesListState extends State<CategoriesList> {
final t = Translations.of(context);

return DefaultTabController(
length: 2,
initialIndex: 1,
child: StreamBuilder(
length: 2,
initialIndex: 1,
child: StreamBuilder(
stream: CategoryService.instance.getMainCategories(),
builder: (context, categoriesSnapshot) {
return Scaffold(
appBar: AppBar(
elevation: 0,
bottom: TabBar(tabs: [
Tab(text: t.transaction.types.income(n: 10)),
Tab(text: t.transaction.types.expense(n: 10)),
]),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
if (widget.mode == CategoriesListMode.page) {
return Scaffold(
appBar: AppBar(
elevation: 0,
bottom: TabBar(tabs: [
Tab(text: t.transaction.types.income(n: 10)),
Tab(text: t.transaction.types.expense(n: 10)),
]),
title: Text(t.general.categories),
automaticallyImplyLeading:
widget.mode == CategoriesListMode.page,
leading: Navigator.canPop(context) &&
widget.mode != CategoriesListMode.page
? IconButton(
icon: const Icon(
Icons.close,
),
onPressed: () => Navigator.of(context).pop(),
)
: null,
),
persistentFooterButtons: [
PersistentFooterButton(
child: FilledButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const CategoryFormPage()));
},
icon: const Icon(Icons.add),
label: Text(t.categories.create),
),
)
],
body: Column(
children: [
Text(t.general.categories),
if (categoriesSnapshot.hasData &&
widget.mode ==
CategoriesListMode.modalSelectMultiCategory)
Builder(builder: (context) {
if (categoriesSnapshot.data!.every((mainCat) =>
selectedCategories
.map((e) => e.id)
.contains(mainCat.id))) {
Builder(builder: (context) {
if (!categoriesSnapshot.hasData) {
return const LinearProgressIndicator();
} else {
return Expanded(
child: TabBarView(children: [
buildCategoryList(
CategoryType.I, categoriesSnapshot.data!),
buildCategoryList(
CategoryType.E, categoriesSnapshot.data!),
]),
);
}
}),
],
),
);
}

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
t.general.categories,
style: Theme.of(context).textTheme.titleLarge,
),
if (categoriesSnapshot.hasData &&
widget.mode ==
CategoriesListMode.modalSelectMultiCategory)
Builder(builder: (context) {
if (categoriesSnapshot.data!.every((mainCat) =>
selectedCategories
.map((e) => e.id)
.contains(mainCat.id))) {
return IconButton(
onPressed: () {
setState(() {
selectedCategories = [];
});
},
icon: const Icon(Icons.deselect),
tooltip: t.general.deselect_all,
);
}

return IconButton(
onPressed: () {
setState(() {
selectedCategories = [];
});
onPressed: () async {
for (final category in categoriesSnapshot.data!) {
await toggleCategorySelection(true, category);
}

setState(() {});
},
icon: const Icon(Icons.deselect),
tooltip: t.general.deselect_all,
icon: const Icon(Icons.select_all),
tooltip: t.general.select_all,
);
})
],
),
),
TabBar(tabs: [
Tab(text: t.transaction.types.income(n: 10)),
Tab(text: t.transaction.types.expense(n: 10)),
]),
Expanded(
child: Stack(
children: [
Builder(builder: (context) {
if (!categoriesSnapshot.hasData) {
return const LinearProgressIndicator();
}

return IconButton(
onPressed: () async {
for (final category in categoriesSnapshot.data!) {
await toggleCategorySelection(true, category);
}

setState(() {});
},
icon: const Icon(Icons.select_all),
tooltip: t.general.select_all,
);
})
],
),
automaticallyImplyLeading:
widget.mode == CategoriesListMode.page,
leading: Navigator.canPop(context) &&
widget.mode != CategoriesListMode.page
? IconButton(
icon: const Icon(
Icons.close,
),
onPressed: () => Navigator.of(context).pop(),
)
: null,
),
persistentFooterButtons: widget.mode == CategoriesListMode.page
? [
PersistentFooterButton(
child: FilledButton.icon(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const CategoryFormPage()));
},
icon: const Icon(Icons.add),
label: Text(t.categories.create),
),
)
]
: null,
body: Column(
children: [
Builder(builder: (context) {
if (!categoriesSnapshot.hasData) {
return const LinearProgressIndicator();
} else {
return Expanded(
child: TabBarView(children: [
return TabBarView(children: [
buildCategoryList(
CategoryType.I, categoriesSnapshot.data!),
buildCategoryList(
CategoryType.E, categoriesSnapshot.data!),
]),
);
}
}),
if (widget.mode ==
CategoriesListMode.modalSelectMultiCategory)
ListView(
shrinkWrap: true,
children: [
const SizedBox(height: 14),
BottomSheetFooter(
onSaved: selectedCategories.isNotEmpty
? () {
return Navigator.of(context)
.pop(selectedCategories);
}
: null,
),
],
)
],
),
]);
}),
if (widget.mode ==
CategoriesListMode.modalSelectMultiCategory)
ScrollableWithBottomGradient.buildPositionedGradient(
Theme.of(context).dialogBackgroundColor),
],
),
),
if (widget.mode == CategoriesListMode.modalSelectMultiCategory)
BottomSheetFooter(
onSaved: selectedCategories.isNotEmpty
? () {
return Navigator.of(context)
.pop(selectedCategories);
}
: null,
),
],
);
}),
);
},
));
}
}
Loading

0 comments on commit bf20f91

Please sign in to comment.