import 'package:flutter/material.dart';
import 'package:fffdesign/util_apis/api_util.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:transparent_image/transparent_image.dart';
final backgroundColor = Color(0xFF435719);
String address="",open="",close="",banner="mybanner.png",restaurantname="",logo='mybanner.png';
class SingleRestaurant extends StatefulWidget {
final String resslug;
SingleRestaurant({Key key,this.resslug}) : super(key: key);
@override
_SingleRestaurantState createState() => _SingleRestaurantState();
}
class _SingleRestaurantState extends State<SingleRestaurant> {
List deal=[];
Future getsingleres() async {
final String url = ApiUtility.Main_Url+ApiUtility.Single_res+widget.resslug;
var res = await http .get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
if (res.statusCode == 200) {
var resBody = json.decode(res.body);
Map data=resBody;
setState(() {
banner= data['users']['banner'];
logo= data['users']['logo'];
restaurantname=data['restaurant_name'];
address=data['address'];
open=data['open'];
close=data['close'];
deal=resBody['deals'];
});
return resBody['deals'];
}else {
// If that call was not successful, throw an error.
throw Exception('Failed to load ');
}
}
@override
void initState() {
super.initState();
this.getsingleres();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: CustomScrollView(
slivers: [
HeaderWidget(),
AlbumWidget(),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'OUR DEALS',
style: Theme.of(context).textTheme.headline3,
),
Text(
'',
style: TextStyle(
color: Colors.pinkAccent, fontSize: 13),
)
],
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate((_, index) {
final Map d = deal[index % deal.length];
return deal.isEmpty ? Center(child: Text('Empty')) : Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
child: Card(
elevation: 2.0,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Image(image: NetworkImage(ApiUtility.Assest_Url+d['dealimage']),
height: 100.0
)
],
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(left: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(d['deal_title'].toString(),overflow: TextOverflow.ellipsis, maxLines: 3,style: Theme.of(context).textTheme.bodyText2),
Row(
children: <Widget>[
Icon(Icons.location_on),
Expanded(child: Text(d['deal_title'].toString(),overflow: TextOverflow.ellipsis, maxLines: 2,style: Theme.of(context).textTheme.bodyText2)),
],
),
Row(
children: <Widget>[
Icon(Icons.restaurant_menu),
Text('Menu Items: 25')
],
)
],
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RaisedButton(
onPressed: () {
},
color: Colors.red,
textColor: Colors.white,
child: Text('add to cart'),)
],
)
],
),
),
),
)
]
);
}, childCount: 20),
),
],
),
),
],
),
);
}
}
class AlbumWidget extends StatelessWidget {
const AlbumWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
children: [
Image.network(
ApiUtility.Assest_Url+logo,
height: 90,
),
const SizedBox(
width: 12,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Location: ${address??''}',
style: TextStyle(
color: Colors.red,
),
),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
color: Colors.red,
child: Text('TIMING Open $open - Close $close'),
onPressed: () => null)
],
),
),
],
),
),
);
}
}
class HeaderWidget extends StatelessWidget {
const HeaderWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SliverAppBar(
expandedHeight: 300,
stretch: true,
backgroundColor: Color(0xFF0B0B14),
flexibleSpace: FlexibleSpaceBar(
stretchModes: [
StretchMode.zoomBackground,
],
background: Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child:FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image:ApiUtility.Assest_Url+banner,fit:BoxFit.cover,
),
),
Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
restaurantname??'',
style: Theme.of(context).textTheme.display1.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
),
);
}
}