Commit b99ba798 authored by Dio Maulana's avatar Dio Maulana

sliver fixed as requirement, pinned

parent 33883b90
......@@ -2,7 +2,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
class MenuSelectedBar extends Cubit<Map<String, dynamic>> {
MenuSelectedBar()
: super({"index": 0, "name": ''}); // default list pertama String 0
: super({"index": 0, "id": ''}); // default list pertama String 0
void selectedBarMenu(int indexBar, String id) {
Map<String, dynamic> result = {
......
......@@ -9,25 +9,30 @@ import 'package:byod/helper/helper.dart';
import 'package:byod/helper/widget/style.dart';
import 'package:byod/models/filter_menu.dart';
import 'package:byod/models/orders.dart';
import 'package:byod/ui/home/variant_cat_new.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:sliver_tools/sliver_tools.dart';
import '../../bloc/filter_menu.dart';
import '../../bloc/order_variant_temporary.dart';
import '../../helper/widget/button_dialog.dart';
import '../../helper/widget/note_modal_bottom_sheet.dart';
import '../../main.dart';
import '../../models/fav_group.dart';
import '../../models/order_variants.dart';
import '../checkout/checkout.dart';
import '../checkout/fuction.dart';
import '../screen_responsive.dart';
import '../viewbill/view_bill.dart';
import 'bottom_sheet_menu.dart';
import 'bottom_sheet_variant.dart';
import 'cat_list.dart';
import 'fav_grid_menu.dart';
import 'fav_list.dart';
import 'package:byod/models/category_list.dart';
import 'menu_list_utama.dart';
import 'shimmer_menu.dart';
class NewHome2 extends StatefulWidget {
......@@ -54,6 +59,7 @@ class _NewHome2State extends State<NewHome2> {
late List<FilterMenu> allMenuFav = [];
List<CategoryList> categoryList = [];
List<CategoryList> categoryListMenu = [];
List<FavoriteGroup> favList = [];
List<FilterMenu> categoryNonFav = [];
List<FilterMenu> categoryFav = [];
......@@ -265,6 +271,7 @@ class _NewHome2State extends State<NewHome2> {
allMenu = categoryNonFav;
allMenuFav = categoryFav;
List<CategoryList> catListTemp = [];
List<CategoryList> catListTempMenu = [];
var nn = {
"name": "All",
"id": "0",
......@@ -281,9 +288,12 @@ class _NewHome2State extends State<NewHome2> {
};
catListTemp
.add(CategoryList.createCategoryList(n));
catListTempMenu
.add(CategoryList.createCategoryList(n));
}
}
categoryList = catListTemp;
categoryListMenu = catListTempMenu;
List<FavoriteGroup> favGroupTemp = [];
for (var nameFav in categoryFav) {
if (nameFav.type == typeCategory) {
......@@ -330,6 +340,7 @@ class _NewHome2State extends State<NewHome2> {
Map<String, dynamic>>(
builder: (contextSelectedBarMenu,
listDynamicBarMenu) {
List<CategoryList> catListMenuTmp = [];
if (isSearchActive) {
if (categoryNonFav.isNotEmpty &&
categoryList.isNotEmpty) {
......@@ -371,10 +382,27 @@ class _NewHome2State extends State<NewHome2> {
}
}
}
for (var nameCatAfterSelect
in categoryMenuAfterSelect) {
if (nameCatAfterSelect.type ==
typeCategory) {
var nn = {
"id": nameCatAfterSelect.id,
"name":
nameCatAfterSelect.categoryName,
};
catListMenuTmp.add(
CategoryList.createCategoryList(
nn));
}
}
categoryListMenu = catListMenuTmp;
} else {
if (categoryNonFav.isNotEmpty &&
categoryList.isNotEmpty) {
List<FilterMenu> temprSelectedMenu = [];
for (var nameCat in categoryNonFav) {
if (nameCat.categoryId ==
listDynamicBarMenu['id']) {
......@@ -388,6 +416,22 @@ class _NewHome2State extends State<NewHome2> {
categoryMenuAfterSelect =
temprSelectedMenu;
}
for (var nameCatAfterSelect
in categoryMenuAfterSelect) {
if (nameCatAfterSelect.type ==
typeCategory) {
var nn = {
"id": nameCatAfterSelect.id,
"name": nameCatAfterSelect
.categoryName,
};
catListMenuTmp.add(
CategoryList.createCategoryList(
nn));
}
}
categoryListMenu = catListMenuTmp;
}
}
......@@ -647,19 +691,461 @@ class _NewHome2State extends State<NewHome2> {
height: spacerAboveMenuItem,
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return MenuListUtama(
categoryNonFav: categoryMenuAfterSelect,
i: index,
widthScreen: widthScreen,
scrollController: _scrollController,
);
},
childCount: categoryMenuAfterSelect.length,
// MultiSliver(pushPinnedChildren: true, children: [
// SliverPinnedHeader(child: Text('Pined1')),
// SliverList(
// delegate: SliverChildListDelegate.fixed(List.generate(
// 100,
// (index) => ListTile(
// title: Text('Ke $index'),
// ))))
// ]),
// MultiSliver(pushPinnedChildren: true, children: [
// SliverPinnedHeader(child: Text('Pined2')),
// SliverList(
// delegate: SliverChildListDelegate.fixed(List.generate(
// 100,
// (index) => ListTile(
// title: Text('Ke $index'),
// ))))
// ]),
for (int i = 0; i < categoryListMenu.length; i++)
MultiSliver(
pushPinnedChildren: true,
children: [
SliverPinnedHeader(
child: Container(
color: backgroundColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
defaultText(
context,
categoryListMenu[i].name,
maxLines: 1,
overFlow: TextOverflow.ellipsis,
style: categoryNameStyle(),
),
const Divider(
thickness: 0.5,
color: textColorBlack,
),
],
),
),
),
for (var menu in categoryMenuAfterSelect)
(menu.categoryId == categoryListMenu[i].id &&
menu.type != typeCategory &&
menu.type == typeGroup)
? Container(
margin: const EdgeInsets.only(
top: 6,
),
child: defaultText(
context,
maxLines: 3,
overFlow: TextOverflow.ellipsis,
categoryNonFav[i].groupName,
style: subCategoryStyle(),
),
)
: (menu.categoryId == categoryListMenu[i].id &&
menu.type != typeCategory &&
menu.type == typeMenu)
? Container(
margin: EdgeInsets.only(
top: 19,
bottom: (i + 1 ==
categoryMenuAfterSelect
.length)
? 85
: 19,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Container(
height: 125,
width: double.infinity,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
defaultText(
context,
menu.name,
style:
menuNameStyle(),
),
const Spacer(),
defaultText(
maxLines: 2,
overFlow: TextOverflow
.ellipsis,
context,
menu.description,
style:
deskripsiMenuStyle(),
),
const SizedBox(
height: 4,
),
defaultText(
maxLines: 1,
overFlow: TextOverflow
.ellipsis,
context,
'Rp ${formatNumber().format(amountParseToInt(menu.price))}',
style:
amountMenuStyle(),
)
],
),
),
Container(
width: 12,
height: double.infinity,
),
GestureDetector(
onTap: () {
FocusScopeNode
currentFocus =
FocusScope.of(
context);
if (!currentFocus
.hasPrimaryFocus) {
currentFocus.unfocus();
}
showModalBottomSheet(
backgroundColor:
Colors.white,
isScrollControlled:
true,
context: context,
builder: (context) {
return ShowMenuModal(
imageUrl: menu
.imageUrlMedium,
namaMenu: menu.name,
hargaMenu:
amountParseToInt(
menu.price),
isHavevariant: menu
.variantCat
.isNotEmpty
? true
: false,
description: menu
.description,
id: menu.id,
variantCat:
menu.variantCat,
isSell: menu.isSell,
);
},
);
},
child: Container(
width: 125,
height: 125,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(14),
color: disabledColor
.withOpacity(0.8),
),
child: ClipRRect(
borderRadius:
BorderRadius
.circular(14),
child:
(menu.imageUrlMedium !=
'')
? Image(
fit: BoxFit
.fill,
image:
NetworkImage(
menu.imageUrlMedium,
),
)
: const Image(
fit: BoxFit
.fill,
image: AssetImage(
'assets/noimage.png'),
),
),
),
)
],
),
),
Container(
height: 8,
width: double.infinity,
),
addRemoveQuantity(context, menu)
],
),
)
: const SizedBox()
],
),
),
// for (int i = 0; i < categoryMenuAfterSelect.length; i++)
// (categoryMenuAfterSelect[i].type == typeCategory)
// ? SliverAppBar(
// shadowColor: Colors.transparent,
// centerTitle: false,
// titleSpacing: 0,
// backgroundColor: backgroundColor,
// automaticallyImplyLeading: false,
// title: defaultText(
// context,
// categoryMenuAfterSelect[i].categoryName,
// maxLines: 1,
// overFlow: TextOverflow.ellipsis,
// style: categoryNameStyle(),
// ),
// pinned: true,
// bottom: const PreferredSize(
// preferredSize: Size.fromHeight(0.5),
// child: Divider(
// thickness: 0.5,
// color: textColorBlack,
// ),
// ),
// )
// // MultiSliver(
// // pushPinnedChildren: true,
// // children: [
// // SliverPinnedHeader(
// // child: Container(
// // color: backgroundColor,
// // child: defaultText(
// // context,
// // categoryMenuAfterSelect[i].categoryName,
// // maxLines: 1,
// // overFlow: TextOverflow.ellipsis,
// // style: categoryNameStyle(),
// // ),
// // ),
// // ),
// // const Divider(
// // thickness: 0.5,
// // color: textColorBlack,
// // ),
// // ],
// // )
// : (categoryMenuAfterSelect[i].type == typeGroup)
// ? MultiSliver(
// pushPinnedChildren: true,
// children: [
// Container(
// margin: const EdgeInsets.only(
// top: 6,
// ),
// child: defaultText(
// context,
// maxLines: 3,
// overFlow: TextOverflow.ellipsis,
// categoryNonFav[i].groupName,
// style: subCategoryStyle(),
// ),
// ),
// ],
// )
// : MultiSliver(
// pushPinnedChildren: true,
// children: [
// Container(
// margin: EdgeInsets.only(
// top: 19,
// bottom: (i + 1 ==
// categoryMenuAfterSelect.length)
// ? 85
// : 19,
// ),
// child: Column(
// crossAxisAlignment:
// CrossAxisAlignment.end,
// children: [
// Container(
// height: 125,
// width: double.infinity,
// child: Row(
// children: [
// Expanded(
// child: Column(
// crossAxisAlignment:
// CrossAxisAlignment
// .start,
// children: [
// defaultText(
// context,
// categoryMenuAfterSelect[
// i]
// .name,
// style: menuNameStyle(),
// ),
// const Spacer(),
// defaultText(
// maxLines: 2,
// overFlow: TextOverflow
// .ellipsis,
// context,
// categoryMenuAfterSelect[
// i]
// .description,
// style:
// deskripsiMenuStyle(),
// ),
// const SizedBox(
// height: 4,
// ),
// defaultText(
// maxLines: 1,
// overFlow: TextOverflow
// .ellipsis,
// context,
// 'Rp ${formatNumber().format(amountParseToInt(categoryMenuAfterSelect[i].price))}',
// style:
// amountMenuStyle(),
// )
// ],
// ),
// ),
// Container(
// width: 12,
// height: double.infinity,
// ),
// GestureDetector(
// onTap: () {
// FocusScopeNode
// currentFocus =
// FocusScope.of(context);
// if (!currentFocus
// .hasPrimaryFocus) {
// currentFocus.unfocus();
// }
// showModalBottomSheet(
// backgroundColor:
// Colors.white,
// isScrollControlled: true,
// context: context,
// builder: (context) {
// return ShowMenuModal(
// imageUrl:
// categoryMenuAfterSelect[
// i]
// .imageUrlMedium,
// namaMenu:
// categoryMenuAfterSelect[
// i]
// .name,
// hargaMenu:
// amountParseToInt(
// categoryMenuAfterSelect[
// i]
// .price),
// isHavevariant:
// categoryMenuAfterSelect[
// i]
// .variantCat
// .isNotEmpty
// ? true
// : false,
// description:
// categoryMenuAfterSelect[
// i]
// .description,
// id: categoryMenuAfterSelect[
// i]
// .id,
// variantCat:
// categoryMenuAfterSelect[
// i]
// .variantCat,
// isSell:
// categoryMenuAfterSelect[
// i]
// .isSell,
// );
// },
// );
// },
// child: Container(
// width: 125,
// height: 125,
// decoration: BoxDecoration(
// borderRadius:
// BorderRadius.circular(
// 14),
// color: disabledColor
// .withOpacity(0.8),
// ),
// child: ClipRRect(
// borderRadius:
// BorderRadius.circular(
// 14),
// child: (categoryMenuAfterSelect[
// i]
// .imageUrlMedium !=
// '')
// ? Image(
// fit: BoxFit.fill,
// image:
// NetworkImage(
// categoryMenuAfterSelect[
// i]
// .imageUrlMedium,
// ),
// )
// : const Image(
// fit: BoxFit.fill,
// image: AssetImage(
// 'assets/noimage.png'),
// ),
// ),
// ),
// )
// ],
// ),
// ),
// Container(
// height: 8,
// width: double.infinity,
// ),
// addRemoveQuantity(
// context, categoryNonFav[i])
// ],
// ),
// ),
// ],
// ),
// SliverList(
// delegate: SliverChildBuilderDelegate(
// (context, index) {
// return MenuListUtama(
// categoryNonFav: categoryMenuAfterSelect,
// i: index,
// widthScreen: widthScreen,
// scrollController: _scrollController,
// );
// },
// childCount: categoryMenuAfterSelect.length,
// ),
// ),
],
),
),
......@@ -1040,6 +1526,318 @@ class _NewHome2State extends State<NewHome2> {
),
);
}
BlocBuilder addRemoveQuantity(BuildContext context, FilterMenu menuUtama) {
List<OrderVariant> orderVariants = [];
return BlocBuilder<OrdersBloc, List<Orders>>(
builder: (contextOrders, list) {
bool
addCondition; // true untuk menampilkan tambah, false untuk menampilkan quantity plus minus
int indexListOrderan =
list.indexWhere((listOrderan) => listOrderan.id == menuUtama.id);
int initialValue;
if (indexListOrderan != -1) {
if (menuUtama.variantCat.isNotEmpty) {
addCondition = true; // kalau menu itu ada variantnya, biarin true
} else {
addCondition = false;
}
initialValue = list[indexListOrderan].totalItem;
} else {
addCondition = true;
initialValue = 0;
}
String variantButtonCount = '';
if (initialValue == 1 && menuUtama.variantCat.isNotEmpty) {
variantButtonCount = '$initialValue Item';
} else if (initialValue > 1 && menuUtama.variantCat.isNotEmpty) {
variantButtonCount = '$initialValue Items';
}
final noteController = TextEditingController(
text: (indexListOrderan != -1) ? list[indexListOrderan].note : '');
return AnimatedSwitcher(
duration: Duration(milliseconds: animatedTime),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child);
},
child: (addCondition)
? Container(
key: const Key('AddButtonMenuKey'),
height: 36,
width: double.infinity,
child: Row(
children: [
const Spacer(),
GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
if (menuUtama.isSell) {
if (menuUtama.variantCat.isNotEmpty) {
if (indexListOrderan == -1) {
context
.read<OrderVariantTemporaryBloc>()
.insertDataVariant(
menuUtama.id,
amountParseToInt(menuUtama.price),
1,
[],
); // check pada bloc untuk mengethui list arraynya
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (_) => VariantCat(
// namaMenu: menuUtama.name,
// variantCategories:
// menuUtama.variantCat,
// initPrice: amountParseToInt(
// menuUtama.price),
// idItem: menuUtama.id,
// imageUrl:
// menuUtama.imageUrlThumbnail,
// listCurrentOrder: list,
// orderDetail: OrderDetail(
// allIdVariant: '',
// totalItem: 0,
// totalHarga: 0,
// note: '',
// orderVariant: [],
// ),
// )));
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => VariantCatNew(
initPrice:
amountParseToInt(menuUtama.price),
variantCategories: menuUtama.variantCat,
),
),
);
} else {
showModalBottomSheet(
backgroundColor: Colors.white.withOpacity(0),
isScrollControlled: true,
context: context,
builder: (context) {
return CustomizeVariant(
orders: list[indexListOrderan],
variantCat: menuUtama.variantCat);
},
);
}
} else {
if (initialValue == 0) {
initialValue += 1;
context.read<OrdersBloc>().insertData([
[
menuUtama.id,
menuUtama.name,
initialValue,
amountParseToInt(menuUtama.price),
list,
menuUtama.imageUrlMedium,
orderVariants,
amountParseToInt(menuUtama.price),
(indexListOrderan != -1)
? list[indexListOrderan].note
: ''
]
], context);
// setState(() {});
}
}
}
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: buttonColor,
),
height: double.infinity,
width: 125,
child: Center(
child: defaultText(
context,
(menuUtama.isSell == false)
? 'Habis'
: (initialValue == 0)
? 'Tambah'
: (initialValue > 0 &&
menuUtama.variantCat.isNotEmpty)
? variantButtonCount
: 'Tambah',
style: addButtonMenu(),
),
),
),
)
],
),
)
: Container(
key: const Key('AddButtonMenuKey'),
height: 36,
width: 125,
child: Row(
children: [
GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
showModalBottomSheet(
backgroundColor: backgroundColor,
isScrollControlled: true,
context: context,
builder: (context) {
return NoteModalBottomSheet(
noteController: noteController,
initialValue: initialValue,
orderVariants: orderVariants,
menuItem: menuUtama,
lisrOrders: list,
);
},
);
},
child: Container(
width: 27,
height: 24,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: buttonColor,
),
child: const Center(
child: Image(
width: 13.33,
height: 13.33,
color: textInButton,
image: AssetImage('assets/icons/note.png'),
),
),
),
),
const SizedBox(
width: 5,
),
Expanded(
child: Container(
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.white,
),
child: Stack(
children: [
Positioned(
left: 0,
child: GestureDetector(
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
if (initialValue > 0) {
initialValue -= 1;
context.read<OrdersBloc>().insertData([
[
menuUtama.id,
menuUtama.name,
initialValue,
amountParseToInt(menuUtama.price),
list,
menuUtama.imageUrlMedium,
orderVariants,
amountParseToInt(menuUtama.price),
(indexListOrderan != -1)
? list[indexListOrderan].note
: ''
]
], context);
// setState(() {});
}
},
child: Container(
width: 22,
height: 22,
child: Image(
color: buttonColor,
image: const AssetImage(
'assets/icons/minus-blue.png'),
),
),
),
),
Positioned(
right: 0,
child: GestureDetector(
onTap: () {
FocusScopeNode currentFocus =
FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
initialValue += 1;
context.read<OrdersBloc>().insertData([
[
menuUtama.id,
menuUtama.name,
initialValue,
amountParseToInt(menuUtama.price),
list,
menuUtama.imageUrlMedium,
orderVariants,
amountParseToInt(menuUtama.price),
(indexListOrderan != -1)
? list[indexListOrderan].note
: '',
]
], context);
},
child: Container(
width: 22,
height: 22,
child: const Image(
image:
AssetImage('assets/icons/plus.png'),
),
),
),
),
Center(
child: Container(
height: 22,
child: Center(
child: defaultText(
context,
initialValue.toString(),
style: amountGridFav(),
),
),
),
),
],
),
),
),
],
),
),
);
},
);
}
}
class Delegate extends SliverPersistentHeaderDelegate {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment