import 'package:diplomaticquarterapp/core/model/pharmacies/PharmacyProduct.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import '../cart-order-page.dart'; class FooterWidget extends StatefulWidget { final bool isAvailble; final int maxQuantity; final int minQuantity; final int quantityLimit; final PharmacyProduct item; final Function addToCartFunction; int price; bool isOverQuantity; FooterWidget(this.isAvailble, this.maxQuantity, this.minQuantity, this.quantityLimit, this.item, {this.price, this.isOverQuantity = false, this.addToCartFunction}); @override _FooterWidgetState createState() => _FooterWidgetState(); } class _FooterWidgetState extends State { double quantityUI = 70; bool showUI = false; @override Widget build(BuildContext context) { return Container( width: double.infinity, height: quantityUI, color: Colors.white, child: Column( children: [ showUI ? Container( width: double.infinity, height: 90, color: Colors.white, child: Container( child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text( TranslationBase.of(context).quantity, style: TextStyle( fontSize: 15, fontWeight: FontWeight.bold), ), ), Container( height: 50.0, child: ListView( scrollDirection: Axis.horizontal, children: [ InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '1', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 1; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '2', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 2; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '3', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 3; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '4', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 4; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '5', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 5; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '6', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 6; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '7', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 7; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '8', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 8; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '9', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 9; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), InkWell( child: Container( alignment: Alignment.center, width: 50.0, color: Colors.white, child: Text( '10', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20), ), ), onTap: () { setState(() { widget.price = 10; if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; return widget.price; } }); }, ), SizedBox( width: 5, ), Container( width: 50.0, child: TextField( decoration: InputDecoration(labelText: 'quantity #'), onChanged: (text) { print(widget.price); print(widget.quantityLimit); if (int.tryParse(text) == null) { text = ''; } else { setState(() { widget.price = int.parse(text); if (widget.price >= widget.quantityLimit) { widget.isOverQuantity = true; } else { widget.isOverQuantity = false; } }); } }, ), ), ], ), ) ], ), ), ) : Container( height: 20, ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 70, height: 50, child: FlatButton( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 4, child: Text( widget.price.toString(), style: TextStyle(fontSize: 20), ), ), Expanded( flex: 5, child: Text( TranslationBase.of(context).quantityShortcut, style: TextStyle(fontSize: 16), ), ), ], ), onPressed: () { setState(() { if (showUI) { quantityUI = 70; showUI = false; } else { quantityUI = 150; showUI = true; } }); }, ), ), Container( width: MediaQuery.of(context).size.width* 0.4, child: SecondaryButton( label: TranslationBase.of(context).addToCart.toUpperCase(), disabled: !widget.isAvailble && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null, onTap: () { widget.addToCartFunction(widget.price, widget.item.id, context); }, borderRadius: 5, color:Colors.green, ), ), SizedBox( width: 5, ), Container( width: MediaQuery.of(context).size.width* 0.3, child: SecondaryButton( label: TranslationBase.of(context).buyNow.toUpperCase(), disabled: !widget.isAvailble && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null, onTap: () { widget.addToCartFunction( widget.price, widget.item.id, context); Navigator.push( context, FadePage(page: CartOrderPage()), ); }, borderRadius: 5, color: !widget.isAvailble && widget.price > 0 || widget.price > widget.quantityLimit || widget.item.rxMessage != null?Colors.grey:Colors.grey[800], ), ), ], ), ], ), ); } }