Skip to content

Commit

Permalink
Merge pull request #5 from RainbowBid/feature3/category-filter
Browse files Browse the repository at this point in the history
Refactor view-all-items page to a staless widget in order to use it i…
  • Loading branch information
Edi013 authored Mar 20, 2024
2 parents db3e2ca + 447b07b commit 4746a52
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 130 deletions.
59 changes: 3 additions & 56 deletions lib/ui/views/home/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:rainbowbid_frontend/ui/widgets/app_primitives/app_sidebar.dart';
import 'package:stacked/stacked.dart';
import 'package:rainbowbid_frontend/ui/views/home/home_viewmodel.dart';

import '../view_items/view_items_view.dart';

class HomeView extends StackedView<HomeViewModel> {
const HomeView({super.key});

Expand All @@ -24,62 +26,7 @@ class HomeView extends StackedView<HomeViewModel> {
),
Expanded(
child: Center(
child: SizedBox(
width: kdDesktopMaxContentWidth,
height: kdDesktopMaxContentHeight,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
verticalSpaceLarge,
Column(
children: [
const Text(
'Hello, DESKTOP UI!',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.w900,
),
),
verticalSpaceMedium,
MaterialButton(
color: Colors.black,
onPressed: viewModel.incrementCounter,
child: Text(
viewModel.counterLabel,
style: const TextStyle(color: Colors.white),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MaterialButton(
color: kcDarkGreyColor,
onPressed: viewModel.showDialog,
child: const Text(
'Show Dialog',
style: TextStyle(
color: Colors.white,
),
),
),
MaterialButton(
color: kcDarkGreyColor,
onPressed: viewModel.showBottomSheet,
child: const Text(
'Show Bottom Sheet',
style: TextStyle(
color: Colors.white,
),
),
),
],
)
],
),
),
child: ViewItemsView(),
),
),
],
Expand Down
132 changes: 62 additions & 70 deletions lib/ui/views/view_items/view_items_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,84 @@ import 'package:stacked/stacked.dart';
import '../../../models/items/item.dart';
import '../../common/app_colors.dart';
import '../../common/app_constants.dart';
import '../../widgets/app_primitives/app_sidebar.dart';
import 'view_items_viewmodel.dart';

class ViewItemsView extends StackedView<ViewItemsViewModel> {
class ViewItemsView extends StatelessWidget {
const ViewItemsView({super.key});

@override
Widget builder(
BuildContext context,
ViewItemsViewModel viewModel,
Widget? child,
) {
return Scaffold(
body: viewModel.isBusy
Widget build(BuildContext context) {
return ViewModelBuilder<ViewItemsViewModel>.reactive(
builder: (context, viewModel, child) => viewModel.isBusy
? const CircularProgressIndicator()
: Column(
children: [
const Text("Your items"),
DropdownButtonFormField<Category>(
value: viewModel.selectedCategory,
onChanged: (value) async {
if (value != null) {
viewModel.selectedCategory = value;
await viewModel.refresh();
}
},
items: Category.values
.map(
(category) => DropdownMenuItem(
value: category,
child: Text(
category.displayValue,
style: const TextStyle(
fontSize: kdFieldLabelFontSize,
),
children: [
const Text("Your items"),
DropdownButtonFormField<Category>(
value: viewModel.selectedCategory,
onChanged: (value) async {
if (value != null) {
viewModel.selectedCategory = value;
await viewModel.refresh();
}
},
items: Category.values
.map(
(category) => DropdownMenuItem(
value: category,
child: Text(
category.displayValue,
style: const TextStyle(
fontSize: kdFieldLabelFontSize,
),
),
)
.toList(),
decoration: const InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.auto,
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: kcLightGrey),
borderRadius: BorderRadius.all(
Radius.circular(
kdFieldBorderRadius,
),
),
),
label: Text(
'Category',
style: TextStyle(
fontSize: kdFieldLabelFontSize,
color: kcMediumGrey,
)
.toList(),
decoration: const InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.auto,
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: kcLightGrey),
borderRadius: BorderRadius.all(
Radius.circular(
kdFieldBorderRadius,
),
),
),
label: Text(
'Category',
style: TextStyle(
fontSize: kdFieldLabelFontSize,
color: kcMediumGrey,
),
),
),
Expanded(
child: ListView.builder(
itemCount: viewModel.data!.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(
viewModel.data![index].brief.toString(),
),
subtitle: Text(
viewModel.data![index].description.toString(),
),
trailing: Text(
viewModel.data![index].category.displayValue,
),
),
Expanded(
child: ListView.builder(
itemCount: viewModel.data!.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
title: Text(
viewModel.data![index].brief.toString(),
),
);
},
),
subtitle: Text(
viewModel.data![index].description.toString(),
),
trailing: Text(
viewModel.data![index].category.displayValue,
),
),
);
},
),
],
),
),
],
),
viewModelBuilder: () => ViewItemsViewModel(),
);
}

@override
ViewItemsViewModel viewModelBuilder(
BuildContext context,
) =>
ViewItemsViewModel();
}
4 changes: 0 additions & 4 deletions lib/ui/views/view_items/view_items_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ import '../../common/app_constants.dart';

class ViewItemsViewModel extends FutureViewModel<List<Item>> {
final _logger = getLogger('ViewItemsViewModel');
final _sidebarController = SidebarXController(
selectedIndex: kiSidebarViewItemsMenuIndex,
);
final _itemsService = locator<IItemsService>();
final _routerService = locator<RouterService>();
late Category _selectedCategory = Category.all;

Category get selectedCategory => _selectedCategory;
SidebarXController get sidebarController => _sidebarController;

set selectedCategory(Category value) {
_selectedCategory = value;
Expand Down

0 comments on commit 4746a52

Please sign in to comment.