Skip to content

Commit

Permalink
feat: add more products
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dyakov committed Dec 19, 2022
1 parent b331c3d commit 839dd13
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 147 deletions.
155 changes: 79 additions & 76 deletions lib/src/feature/shop/page/products_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,90 +25,93 @@ class ShopProductsPage extends StatelessWidget {
shop: shop,
child: BlocBuilder<ProductsBloc, ProductsState>(
builder: (context, state) => Scaffold(
body: ListView(
physics: const BouncingScrollPhysics(),
children: [
const SizedBox(height: 30),
ShopCardWidget(
shop: shop,
descriptionMaxLines: 3,
backgroundColor: Colors.transparent,
showDeliveryInfo: false,
onTap: () {},
),
const SizedBox(height: 20),
SearchWidget(
hint: 'Search for a product in ${shop.name}',
onChanged: (String query) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.searchProduct(
query: query,
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: kDefaultPadding,
right: kDefaultPadding,
top: 3,
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: ListView(
physics: const BouncingScrollPhysics(),
children: [
ShopCardWidget(
shop: shop,
descriptionMaxLines: 3,
backgroundColor: Colors.transparent,
showDeliveryInfo: false,
onTap: () {},
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DeliveryInfoWidget(
color: Colors.grey,
deliveryPrice: shop.deliveryPrice,
deliveryTime: shop.deliveryTimeInMinutes,
),
const SizedBox(height: 20),
FiltersWidget(
const SizedBox(height: 20),
SearchWidget(
hint: 'Search for a product in ${shop.name}',
onChanged: (String query) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.searchProduct(
query: query,
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
onFiltersChanged: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.changeValues(
weightValues: weightValues,
priceValues: priceValues,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: kDefaultPadding,
right: kDefaultPadding,
top: 3,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DeliveryInfoWidget(
color: Colors.grey,
deliveryPrice: shop.deliveryPrice,
deliveryTime: shop.deliveryTimeInMinutes,
),
onFiltersChangeEnd: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.searchProduct(
query: state.data.query,
weightValues: weightValues,
priceValues: priceValues,
const SizedBox(height: 20),
FiltersWidget(
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
onFiltersChanged: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.changeValues(
weightValues: weightValues,
priceValues: priceValues,
),
),
onFiltersChangeEnd: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ProductsBloc>(context).add(
ProductsEvent.searchProduct(
query: state.data.query,
weightValues: weightValues,
priceValues: priceValues,
),
),
),
),
const SizedBox(height: 30),
state.when(
initial: (data) => Column(
children: [
const TitleWidget('All products'),
ProductsBuilder(products: data.shop.products),
],
),
failure: (data, error) => TitleWidget(error),
searchSuccess: (results, data) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Search Results'),
ProductsBuilder(products: results),
],
const SizedBox(height: 30),
state.when(
failure: (data, error) => TitleWidget(error),
initial: (data) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('All products'),
ProductsBuilder(products: data.shop.products),
],
),
searchSuccess: (results, data) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Search Results'),
ProductsBuilder(products: results),
],
),
),
),
],
],
),
),
),
],
],
),
),
),
),
Expand Down
140 changes: 75 additions & 65 deletions lib/src/feature/shop/page/shops_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,81 +17,91 @@ class ShopsPage extends StatelessWidget {
Widget build(BuildContext context) => ShopsScope(
child: BlocBuilder<ShopsBloc, ShopsState>(
builder: (context, state) => Scaffold(
body: ListView(
physics: const BouncingScrollPhysics(),
children: [
const SizedBox(height: 30),
SearchWidget(
onChanged: (String query) =>
BlocProvider.of<ShopsBloc>(context).add(
ShopsEvent.searchProduct(
query: query,
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
),
),
hint: 'Search for a product in all shops',
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: kDefaultPadding,
),
child: FiltersWidget(
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
onFiltersChanged: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ShopsBloc>(context).add(
ShopsEvent.changeValues(
weightValues: weightValues,
priceValues: priceValues,
),
),
onFiltersChangeEnd: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 30),
child: ListView(
physics: const BouncingScrollPhysics(),
children: [
SearchWidget(
onChanged: (String query) =>
BlocProvider.of<ShopsBloc>(context).add(
ShopsEvent.searchProduct(
query: state.data.query,
weightValues: weightValues,
priceValues: priceValues,
query: query,
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
),
),
hint: 'Search for a product in all shops',
),
),
const SizedBox(height: 30),
state.when(
loading: (data) => const Center(
child: CircularProgressIndicator(
color: Colors.black,
),
),
loadSuccess: (data) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Available Shops'),
ShopsBuilder(shops: data.shops),
],
),
failure: (data, error) => TitleWidget(error),
searchSuccess: (data, products) => Padding(
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: kDefaultPadding,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Search Results'),
ProductsBuilder(products: products),
],
child: FiltersWidget(
weightValues: state.data.weightValues,
priceValues: state.data.priceValues,
onFiltersChanged: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ShopsBloc>(context).add(
ShopsEvent.changeValues(
weightValues: weightValues,
priceValues: priceValues,
),
),
onFiltersChangeEnd: (
SfRangeValues weightValues,
SfRangeValues priceValues,
) =>
BlocProvider.of<ShopsBloc>(context).add(
ShopsEvent.searchProduct(
query: state.data.query,
weightValues: weightValues,
priceValues: priceValues,
),
),
),
),
const SizedBox(height: 30),
state.when(
failure: (data, error) => TitleWidget(
error,
horizontalPadding: kDefaultPadding,
),
loading: (data) => const Center(
child: CircularProgressIndicator(
color: Colors.black,
),
),
loadSuccess: (data) => Padding(
padding: const EdgeInsets.symmetric(
horizontal: kDefaultPadding,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Available Shops'),
ShopsBuilder(shops: data.shops),
],
),
),
searchSuccess: (data, products) => Padding(
padding: const EdgeInsets.symmetric(
horizontal: kDefaultPadding,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TitleWidget('Search Results'),
ProductsBuilder(products: products),
],
),
),
),
),
],
],
),
),
),
),
Expand Down
Loading

0 comments on commit 839dd13

Please sign in to comment.