Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- part of 'pages.dart';
- class DetailRestaurant extends StatefulWidget {
- static const routeName = '/detail_restaurant_page';
- final String id;
- DetailRestaurant({required this.id});
- @override
- _DetailRestaurantState createState() => _DetailRestaurantState();
- }
- class _DetailRestaurantState extends State<DetailRestaurant> {
- TextEditingController _nameController = TextEditingController();
- TextEditingController _reviewController = TextEditingController();
- late Future<void> postReview;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: _buildContentDetail(),
- );
- }
- Widget _buildContentDetail() {
- return ChangeNotifierProvider<DetailRestaurantProvider>(
- create: (_) =>
- DetailRestaurantProvider(apiService: ApiService(), id: widget.id),
- child: Consumer<DetailRestaurantProvider>(
- builder: (context, state, _) {
- if (state.state == ResultState.Loading) {
- return Loading();
- } else if (state.state == ResultState.HasData) {
- var detail = state.detailRestaurant.restaurant;
- return Stack(
- children: [
- Container(
- color: Colors.white,
- ),
- SafeArea(
- child: Container(
- color: Colors.white,
- )),
- SafeArea(
- child: Container(
- height: 300,
- width: double.infinity,
- decoration: BoxDecoration(
- image: DecorationImage(
- image: NetworkImage(
- ApiService.baseUrlImage + detail!.pictureId),
- fit: BoxFit.cover)),
- )),
- SafeArea(
- child: ListView(
- children: [
- Column(
- children: [
- Container(
- height: 80,
- child: Align(
- alignment: Alignment.centerLeft,
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: <Widget>[
- MaterialButton(
- color: Colors.white,
- shape: CircleBorder(),
- onPressed: () {
- Navigator.pop(context);
- },
- child: Padding(
- padding: const EdgeInsets.all(2),
- child: Icon(Icons.arrow_back,
- color: mainColor),
- ),
- ),
- MaterialButton(
- color: Colors.white,
- shape: CircleBorder(),
- onPressed: () {
- Share.share(
- "${detail.name}\nLocation: ${detail.city}\n${ApiService.baseUrlImage}${detail.pictureId}" );
- },
- child: Padding(
- padding: const EdgeInsets.all(2),
- child: Icon(Icons.share,
- color: mainColor),
- ),
- ),
- ]),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 200),
- padding: EdgeInsets.symmetric(
- vertical: 26, horizontal: defaultMargin),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(24),
- topRight: Radius.circular(24)),
- color: Colors.white),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- detail.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: textFontStyle2.copyWith(
- fontWeight: FontWeight.bold),
- ),
- Rating(detail.rating),
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 8),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Icon(Icons.place,
- size: 16, color: mainColor),
- SizedBox(
- width: 3,
- ),
- Expanded(
- child: Text(
- detail.city,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- style: subTextFontStyle.copyWith(
- fontSize: 13),
- ),
- )
- ])),
- Container(
- height: 40,
- margin: EdgeInsets.only(top: 6),
- width: double.infinity,
- child: ListCategories(
- categories: detail.categories)),
- Container(
- margin: EdgeInsets.only(top: 8, bottom: 10),
- child: Text(
- detail.description,
- style:
- subTextFontStyle.copyWith(fontSize: 13),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 4, bottom: 4),
- child: Row(children: [
- Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- Text(
- 'Foods Menu',
- style: textFontStyle3.copyWith(
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- ])
- ])),
- Container(
- height: 130,
- width: double.infinity,
- child: ListMenus.food(
- foods: detail.menus?.foods)),
- Container(
- margin: EdgeInsets.only(top: 4, bottom: 4),
- child: Row(children: [
- Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- Text(
- 'Drinks Menu',
- style: textFontStyle3.copyWith(
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- ])
- ])),
- Container(
- height: 130,
- width: double.infinity,
- child: ListMenus.drink(
- drinks: detail.menus?.drinks)),
- Container(
- margin: EdgeInsets.only(top: 4, bottom: 4),
- child: Row(children: [
- Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- Text(
- 'Customer Reviews',
- style: textFontStyle3.copyWith(
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- ])
- ])),
- Container(
- height: (detail.consumerReviews?.length == 1)
- ? 60
- : 120,
- width: double.infinity,
- child: (detail.consumerReviews?.length != 0)
- ? ListReviews(
- reviews: detail.consumerReviews)
- : Column(
- mainAxisAlignment:
- MainAxisAlignment.center,
- crossAxisAlignment:
- CrossAxisAlignment.center,
- children: [
- Container(
- child: Text('No Review',
- style: subTextFontStyle
- .copyWith(
- fontSize: 12)))
- ],
- )),
- Container(
- height: 65,
- padding: EdgeInsets.fromLTRB(0, 12, 0, 8),
- child:
- TextField(
- style: textFontStyle3.copyWith(fontSize: 14),
- controller: _nameController,
- decoration: InputDecoration(
- labelText: 'Name',
- hintText: 'Name',
- labelStyle: TextStyle(
- color: mainColor,
- ),
- border: OutlineInputBorder(
- borderSide: BorderSide(color: mainColor),
- ),
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: mainColor),
- ),
- suffixIcon: Icon(
- Icons.person,
- color: mainColor,
- ),
- contentPadding: EdgeInsets.fromLTRB(12, 8, 12, 2)
- ),
- )
- ),
- Container(
- height: 70,
- padding: EdgeInsets.fromLTRB(0, 2, 0, 2),
- child:
- TextField(
- style: textFontStyle3.copyWith(fontSize: 14),
- controller: _reviewController,
- maxLines: 2,
- decoration: InputDecoration(
- labelText: 'Review',
- hintText: 'Review',
- labelStyle: TextStyle(
- color: mainColor,
- ),
- border: OutlineInputBorder(
- borderSide: BorderSide(color: mainColor),
- ),
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(color: mainColor),
- ),
- suffixIcon: Icon(
- Icons.reviews,
- color: mainColor,
- ),
- contentPadding: EdgeInsets.fromLTRB(12, 8, 12, 2)
- ),
- )
- ),
- Container(
- height: 50,
- width: double.infinity,
- child:
- ElevatedButton(
- child: Text(
- 'Submit Review',
- style: textFontStyle3.copyWith(color: Colors.white),
- ),
- style: ElevatedButton.styleFrom(
- primary: mainColor,
- minimumSize: Size(88, 36),
- padding: EdgeInsets.symmetric(horizontal: 16),
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.all(Radius.circular(8)),
- ),
- ),
- onPressed: () {
- setState(() {
- ConsumerReviewPost data = ConsumerReviewPost(
- id: widget.id,
- name: _nameController.text,
- review: _reviewController.text);
- postReview = Provider.of<DetailRestaurantProvider>(context, listen: false).postReview(data);
- _nameController.clear();
- _reviewController.clear();
- Navigator.pushReplacement(
- context,
- MaterialPageRoute(
- builder: (BuildContext context) => super.widget));
- // Scaffold.of(context).showSnackBar(
- // SnackBar(
- // content: Text("Data Berhasil disimpan"),
- // ),
- // );
- });
- },
- ),
- ),
- ],
- ),
- )
- ],
- )
- ],
- ))
- ],
- );
- } else if (state.state == ResultState.NoData) {
- return NoData();
- } else if (state.state == ResultState.Error) {
- return Error(message: state.message);
- } else {
- return Center(child: Text(''));
- }
- }
- )
- );
- }
- @override
- void dispose() {
- super.dispose();
- _nameController.dispose();
- _reviewController.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement