Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.97 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_svg/svg.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:supplier/expired_product_notifier.dart';
  5. import 'package:supplier/util.dart';
  6.  
  7. class ProductItemCheckout extends StatefulWidget {
  8. final ExpiredProduct expiredProduct;
  9. ProductItemCheckout(this.expiredProduct);
  10.  
  11. @override
  12. _ProductItemCheckoutState createState() => _ProductItemCheckoutState();
  13. }
  14.  
  15. class _ProductItemCheckoutState extends State<ProductItemCheckout> {
  16. TextEditingController _dateController = TextEditingController();
  17. TextEditingController _quantityController = TextEditingController();
  18.  
  19. List<Widget> tanggalKadaluarsaWidgets(ExpiredProductNotifier bn) {
  20. return widget.expiredProduct.expiredQuantities.map((item) {
  21. _dateController.text = item.expired == null ? '' : Util.format(item.expired);
  22. _quantityController.text = item.quantity.toString() == null ? '' : item.quantity.toString();
  23.  
  24. DateTime now = DateTime.now();
  25. return Padding(
  26. padding: const EdgeInsets.only(bottom: 8.0),
  27. child: Row(
  28. children: <Widget>[
  29. Container(
  30. width: 190,
  31. height: 44,
  32. child: TextFormField(
  33. style: TextStyle(fontSize: 14, color: Color(0xFF4F4F4F)),
  34. controller: _dateController,
  35. decoration: InputDecoration(
  36. contentPadding: EdgeInsets.all(8),
  37. suffixIcon: Padding(
  38. padding: EdgeInsetsDirectional.only(top: 8, bottom: 8),
  39. child: SvgPicture.asset('assets/calendar.svg')),
  40. enabledBorder: OutlineInputBorder(
  41. borderSide: BorderSide(color: Colors.grey),
  42. borderRadius: BorderRadius.circular(4)
  43. ),
  44. focusedBorder: OutlineInputBorder(
  45. borderSide: BorderSide(color: Color(0xFF68C93E)),
  46. borderRadius: BorderRadius.circular(4)
  47. )
  48. ),
  49. onTap: () async {
  50. now = await
  51. showDatePicker(
  52. context: context,
  53. initialDate: now,
  54. firstDate: now,
  55. lastDate: DateTime(DateTime.now().year + 1),
  56. builder: (BuildContext context, Widget child) {
  57. return Theme(
  58. child: child,
  59. data: ThemeData.light().copyWith(
  60. primaryColor: Color(0xFF68C93E),
  61. accentColor: Color(0xFF68C93E)
  62. ),
  63. );
  64. },
  65. );
  66. bn.setDate(widget.expiredProduct.product, item.id, now);
  67. _dateController.text = Util.format(now);
  68. }
  69. ),
  70. ),
  71. SizedBox(width: 17),
  72. Container(
  73. width: 70,
  74. height: 44,
  75. child: TextFormField(
  76. cursorColor: Color(0xFF68C93E),
  77. keyboardType: TextInputType.number,
  78. style: TextStyle(fontSize: 14, color: Color(0xFF4F4F4F)), textAlign: TextAlign.center,
  79. controller: _quantityController,
  80. decoration: InputDecoration(
  81. contentPadding: EdgeInsets.all(8),
  82. enabledBorder: OutlineInputBorder(
  83. borderSide: BorderSide(color: Colors.grey),
  84. borderRadius: BorderRadius.circular(4)
  85. ),
  86. focusedBorder: OutlineInputBorder(
  87. borderSide: BorderSide(color: Color(0xFF68C93E)),
  88. borderRadius: BorderRadius.circular(4)
  89. ),
  90. ),
  91. onTap: () async {
  92. bn.setQuantity(widget.expiredProduct.product, item.id, _quantityController);
  93. },
  94. ),
  95. ),
  96. SizedBox(width: 27),
  97. InkWell(
  98. onTap: () {
  99. bn.deleteExpired(widget.expiredProduct);
  100. },
  101. child: Icon(Icons.clear, color: Colors.grey)
  102. ),
  103.  
  104. ],
  105. ),
  106. );
  107. }).toList();
  108. }
  109.  
  110. @override
  111. Widget build(BuildContext context) {
  112. return Consumer<ExpiredProductNotifier>(
  113. builder: (_, bn, __) {
  114. return Container(
  115. color: Colors.white,
  116. padding: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 8.0),
  117. child: Column(
  118. children: <Widget>[
  119. Row(
  120. mainAxisAlignment: MainAxisAlignment.start,
  121. crossAxisAlignment: CrossAxisAlignment.start,
  122. children: <Widget> [
  123. Icon(Icons.check_circle, color: Color(0xFF68C93E), size: 20),
  124. SizedBox(width: 16),
  125. Container(
  126. height: 77.0,
  127. width: 77.0,
  128. decoration: BoxDecoration(
  129. image: DecorationImage(
  130. image: NetworkImage(widget.expiredProduct.product.thumbnail),
  131. fit: BoxFit.fill,
  132. ),
  133. border: Border.all(color: Color(0xFF68C93E)),
  134. borderRadius: BorderRadius.circular(5)
  135. ),
  136. ),
  137. SizedBox(width: 16),
  138. Expanded(
  139. child: Column(
  140. crossAxisAlignment: CrossAxisAlignment.start,
  141. children: <Widget>[
  142. Text(
  143. widget.expiredProduct.product.name,
  144. style: TextStyle(color: Color(0xFF4F4F4F), fontWeight: FontWeight.bold),
  145. textAlign: TextAlign.left,
  146. maxLines: 2),
  147. SizedBox(height: 24),
  148. Row(
  149. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  150. children: <Widget>[
  151. Text('Stok: 50 Karton', style: TextStyle(fontSize: 14, color: Color(0xFF4F4F4F))),
  152. InkWell(
  153. onTap: () {
  154. bn.deleteProduct(widget.expiredProduct.product);
  155. },
  156. child: SvgPicture.asset('assets/trash_fill.svg'))
  157. ],
  158. )
  159. ],
  160. ),
  161. ),
  162. ],
  163. ),
  164. SizedBox(height: 16.0),
  165. Divider(),
  166. Column(
  167. crossAxisAlignment: CrossAxisAlignment.start,
  168. children: <Widget>[
  169. FlatButton(
  170. onPressed: () {
  171. bn.addExpired(widget.expiredProduct);
  172. },
  173. color: Color(0xFF68C93E),
  174. child: Text('+ Tambah Tanggal Kadaluarsa', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
  175. shape: RoundedRectangleBorder(
  176. borderRadius: BorderRadius.circular(14)
  177. ),
  178. ),
  179. SizedBox(height: 16.0),
  180. Row(
  181. children: <Widget>[
  182. Text('Tanggal Kadaluarsa', style: TextStyle(color: Color(0xFF4F4F4F), fontWeight: FontWeight.bold)),
  183. SizedBox(width: 80),
  184. Text('Jumlah SKU', style: TextStyle(color: Color(0xFF4F4F4F), fontWeight: FontWeight.bold))
  185. ],
  186. ),
  187. SizedBox(height: 16.0),
  188. ...tanggalKadaluarsaWidgets(bn)],
  189. )
  190. ],
  191. ),
  192. );
  193. }
  194. );
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement