Widget _buildSliverAppbarBackground(
BuildContext context,) {
var imageList = restaurantDetail.image;
return Column(
children: [
Stack(
children: [
Image.network(
document.data()['image'],
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height / 4,
),
Positioned(
child: IconButton(
icon: Icon(
Icons.favorite_border,
color: Colors.white,
size: 32,
),
onPressed: () {},
),
right: 16,
top: 32,
),
Positioned(
child: Container(
decoration:
BoxDecoration(color: Colors.white, shape: BoxShape.circle),
child: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
),
),
left: 16,
top: 32,
),
],
),
SizedBox(
height: 16,
),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Text(
document.data()['name'] ?? "",
textAlign: TextAlign.start,
style: Theme.of(context)
.textTheme
.headline5
.copyWith(fontWeight: FontWeight.bold),
)),
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Text(
_getFoodSpeciality(),
textAlign: TextAlign.start,
)),
Container(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
_getApproximateTime(),
SizedBox(width: 4),
// Text("4.5"),
// SizedBox(width: 4),
Icon(Icons.star_border, color: Colors.amber, size: 16),
SizedBox(width: 4),
Text("4.5"),
SizedBox(width: 4),
Text("(126) "),
SizedBox(width: 4),
_getApproximateDeliveryFee(),
],
)),
Container(
decoration: BoxDecoration(
border: Border.all(width: 1),
borderRadius: BorderRadius.all(Radius.circular(8))),
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: ListTile(
leading: Icon(
Icons.fire_extinguisher,
color: Colors.purple,
),
title: Text("5 orders earn \$12 reward"),
subtitle: Text("\$15 minimum"),
trailing: IconButton(
icon: Icon(
Icons.arrow_forward_ios,
),
onPressed: () {}),
),
),
Divider(thickness: 2),
ListTile(
title: Text(
"Store Info",
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontWeight: FontWeight.bold),
),
trailing: InkWell(
child: Text(
"More Info",
style: TextStyle(color: Colors.green),
),
),
subtitle: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Icon(Icons.location_on, size: 16),
Expanded(
child: Text(
"${restaurantDetail.address.formatted}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
)),
],
),
),
),
Divider(thickness: 2),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Menu",
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontWeight: FontWeight.bold)),
IconButton(
icon: Icon(Icons.search_sharp),
onPressed: () {},
),
],
),
)
],
);
}
Widget _buildSliverAppbar(BuildContext context) {
var size = MediaQuery.of(context).size;
return SliverAppBar(
brightness: Brightness.light,
backgroundColor: Colors.white,
pinned: true,
snap: false,
expandedHeight: size.height / 1.33,
leading: !isExpanded
? IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
),
onPressed: () => Navigator.of(context).pop(),
)
: Container(),
actions: [
!isExpanded
? IconButton(
icon: Icon(
Icons.search,
size: 32,
color: Colors.black,
),
onPressed: () {
_showSearchSection(context);
},
)
: Container(),
],
title: !isExpanded
? Text(
'fromfirebase' ?? "",
style: TextStyle(color: Colors.black),
)
: Container(),
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.parallax,
// title: !isExpanded ? Text("Detail View",style: TextStyle(color: blackColor),) : Container(),
background: _buildSliverAppbarBackground(context),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(40),
child: AnimatedOpacity(
duration: Duration(milliseconds: 500),
opacity: isExpanded ? 0.0 : 1,
child: TabBar(
controller: _tabController,
labelStyle:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
labelColor: Colors.black,
indicatorColor: Colors.black,
indicatorWeight: 2.5,
isScrollable: true,
indicatorPadding: EdgeInsets.symmetric(horizontal: 4),
onTap: (index) async {
_scrollToIndex(index);
},
tabs: foodItems?.data?.map((e) {
return Tab(
child: Text("${
e.name}"),
//from firebase // text: 'Detail Business',
// icon: Icon(Icons.three_k,color: whiteColor,),
);
})?.toList(),
),
),
),
);
}
@override
Widget build(BuildContext context) {
super.build(context);
var size = MediaQuery.of(context).size;
return Scaffold(
body: CustomScrollView(
controller: _autoScrollController,
// shrinkWrap: true,
slivers: <Widget>[
_buildSliverAppbarBackground(context),
SliverList(
delegate: SliverChildListDelegate(
[
_buildFoodCategoryBody(context),
],
)),
],
));
}
ListView _buildFoodCategoryBody(BuildContext context) {
return ListView.builder(
// itemScrollController: itemScrollController,
// itemPositionsListener: itemPositionsListener,
shrinkWrap: true,
addAutomaticKeepAlives: true,
physics: NeverScrollableScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (context, index) => VisibilityDetector(
key: Key(snapshot.data[index]),
onVisibilityChanged: (info) {
// if (!_autoScrollController.isAutoScrolling) return;
var visiblePercentage = info.visibleFraction * 100;
if (visiblePercentage > 90) {
_visibleItems.putIfAbsent(index, () => true);
} else {
_visibleItems.remove(index);
}
_calculateIndexAndJumpToTab(_visibleItems);
},
child: _wrapScrollTag(
index: index,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
alignment: Alignment.centerLeft,
padding: EdgeInsets.all(8),
child: Text(document['name'] ?? "Picked for you",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(fontWeight: FontWeight.bold)),
),
SizedBox(
height: 16,
),
//..._buildCategoryItems(context, index, snapshot),
],
),
),
),
);
}
List<Widget> _buildCategoryItems(
BuildContext context, int index, AsyncSnapshot snapshot) {
if (snapshot.data[index]['foodCategory'].isEmpty) return [Container()];
List<Widget> _list = [];
for (int i = 0; i < foodItems.data[index].foods.length; i++) {
_list.add(_buildSingleFoodItemByCategory(
context, foodItems.data[index].foods[i]));
}
return _list;
}
InkWell _buildSingleFoodItemByCategory(BuildContext context, Foods food) {
return InkWell(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
child: Text(
style: Theme.of(context).textTheme.subtitle2,
textAlign: TextAlign.start,
),
alignment: Alignment.centerLeft,
),
SizedBox(
height: 8,
),
Container(
alignment: Alignment.centerLeft,
child: Text(
food.subTitle,
textAlign: TextAlign.start,
),
),
SizedBox(
height: 8,
),
Container(
child: Text(
"\$${food.price}",
style: Theme.of(context).textTheme.subtitle2,
textAlign: TextAlign.start,
),
alignment: Alignment.centerLeft,
),
],
)),
SizedBox(
width: 8,
),
Expanded(
flex: 1,
child: FadeInImage.assetNetwork(
placeholder: "assets/images/pizza_image.jpg",
image: food.images == null || food.images.isEmpty
? NO_IMAGE_FOUND_URL
: getImageUrlFromApi(food.images.first),
width: MediaQuery.of(context).size.width,
fit: BoxFit.fitHeight,
),
),
],
),
),
Divider(
thickness: 2,
color: Colors.green,
)
],
),
onTap: () {
// todo do something
},
);
}