Advertisement
Guest User

ss

a guest
Jan 17th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 13.52 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'barang_model.dart';
  3. import 'package:flutter_money_formatter/flutter_money_formatter.dart';
  4.  
  5.  
  6. class DetailBarangPage extends StatefulWidget {
  7.  
  8.   final String kodebarang;
  9.  
  10.   const DetailBarangPage(this.kodebarang);
  11.  
  12.   @override
  13.   _DetailBarangPageState createState() => _DetailBarangPageState();
  14. }
  15.  
  16. class _DetailBarangPageState extends State<DetailBarangPage> {
  17.   DataBarang detailbarang;
  18.   String _kodebarang;
  19.  
  20.   @override
  21.   void initState() {
  22.     // TODO: implement initState
  23.     super.initState();
  24.   }
  25.   @override
  26.   Widget build(BuildContext context) {
  27.    
  28.     return Scaffold(
  29.       appBar : AppBar(
  30.         title : Text('Data Barang')
  31.       ),
  32.        body: _buildFieldBarang(),
  33.     );
  34.   }
  35.  
  36.   void ambilData() async {
  37.   final barang = await ApiService().getData(_kodebarang);
  38.    setState((){
  39.      detailbarang = barang;
  40.    });
  41.   }
  42.  
  43.   Widget _buildFieldBarang() {
  44.      _kodebarang = widget.kodebarang;
  45.     ambilData();
  46.     if (detailbarang == null) {
  47.       return Center(child: CircularProgressIndicator());
  48.  
  49.     } else {
  50.       return Container(
  51.         child :SingleChildScrollView(
  52.          
  53.             child: Column(
  54.               mainAxisAlignment: MainAxisAlignment.start,
  55.               crossAxisAlignment: CrossAxisAlignment.start,
  56.          
  57.             children: <Widget>[
  58.                             Padding(padding: EdgeInsets.only(left: 10.0,top: 10.0),
  59.                                   child : Text('Kode Barang',style: TextStyle(fontSize: 16.0),),
  60.                             ),
  61.                             Container(
  62.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  63.                               height: 30.0,
  64.                                   child : TextFormField(
  65.                                     keyboardType: TextInputType.text,
  66.                                     initialValue: detailbarang.data[0].kodebarang.toString(),
  67.                                     enabled: false,              
  68.                                     decoration: InputDecoration(
  69.                                       border: OutlineInputBorder(),
  70.                                     ),
  71.                                   ),
  72.                             ),
  73.                           Padding(
  74.                             padding: EdgeInsets.only(left: 10.0,top: 10.0),
  75.                             child : Text('Nama Barang',style: TextStyle(fontSize: 16.0),),
  76.                             ),
  77.                           Container(
  78.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  79.                               height: 30.0,
  80.                                   child : TextFormField(
  81.                                       keyboardType: TextInputType.text,
  82.                                       initialValue: detailbarang.data[0].namabarang.toString(),
  83.                                       enabled: false,
  84.                                       decoration: InputDecoration(
  85.                                         border: OutlineInputBorder(),
  86.                                   ),
  87.                             ),
  88.                           ),
  89.                           Padding(
  90.                             padding: EdgeInsets.only(left: 10.0,top: 10.0),
  91.                             child : Text('Kategori',),
  92.                           ),
  93.                           Container(
  94.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  95.                               height: 30.0,
  96.                                   child : TextFormField(
  97.                                     keyboardType: TextInputType.text,
  98.                                     initialValue: detailbarang.data[0].namakategori.toString(),
  99.                                     enabled: false,
  100.                                     decoration: InputDecoration(
  101.                                       border: OutlineInputBorder(),
  102.                                     ),
  103.                                 )
  104.                           ),
  105.                           Padding(
  106.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  107.                                         child : Text('Satuan Beli',),
  108.                           ),
  109.                           Container(
  110.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  111.                               height: 30.0,
  112.                                   child : TextFormField(
  113.                                 keyboardType: TextInputType.text,
  114.                                 initialValue: detailbarang.data[0].satuanbeli.toString(),
  115.                                 enabled: false,
  116.                                 decoration: InputDecoration(
  117.                                   border: OutlineInputBorder(),
  118.                                 ),
  119.                               ),          
  120.                           ),
  121.                           Padding(
  122.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  123.                                         child : Text('Isi',),
  124.                           ),
  125.                           Container(
  126.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  127.                               height: 30.0,
  128.                                   child : TextFormField(
  129.                                   keyboardType: TextInputType.text,
  130.                                   initialValue: detailbarang.data[0].isiperbox.toString(),
  131.                                   enabled: false,
  132.                                   decoration: InputDecoration(
  133.                                     border: OutlineInputBorder(),
  134.                                   ),
  135.                                 ),
  136.                           ),
  137.                           Padding(
  138.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  139.                                         child : Text('Satuan Jual',),
  140.                           ),
  141.                           Container(
  142.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  143.                               height: 30.0,
  144.                                   child : TextFormField(
  145.                                   keyboardType: TextInputType.text,
  146.                                   initialValue: detailbarang.data[0].satuanjual.toString(),
  147.                                   enabled: false,
  148.                                   decoration: InputDecoration(
  149.                                     border: OutlineInputBorder(),
  150.                                   ),
  151.                                 ),
  152.                           ),
  153.                           Padding(
  154.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  155.                                         child : Text('Harga Beli',),
  156.                           ),
  157.                           Container(
  158.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  159.                               height: 30.0,
  160.                                   child : TextFormField(
  161.                                   keyboardType: TextInputType.text,
  162.                                   initialValue: formatCur(double.parse(detailbarang.data[0].hargabeli.toString())),
  163.                                   enabled: false,
  164.                                   decoration: InputDecoration(
  165.                                     border: OutlineInputBorder(),
  166.                                   ),
  167.                                 ),
  168.                           ),
  169.                          
  170.                           Padding(
  171.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  172.                                         child : Text('Harga Ecer',),
  173.                           ),
  174.                           Container(
  175.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  176.                               height: 30.0,
  177.                                   child : TextFormField(
  178.                                   keyboardType: TextInputType.text,
  179.                                   initialValue: formatCur(double.parse(detailbarang.data[0].hargaecer.toString())),
  180.                                   enabled: false,
  181.                                   decoration: InputDecoration(
  182.                                     border: OutlineInputBorder(),
  183.                                   ),
  184.                                 ),
  185.                           ),
  186.                          
  187.                           Padding(
  188.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  189.                                         child : Text('Harga Grosir',),
  190.                           ),
  191.                           Container(
  192.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  193.                               height: 30.0,
  194.                                   child : TextFormField(
  195.                                   keyboardType: TextInputType.text,
  196.                                   initialValue: formatCur(double.parse(detailbarang.data[0].hargagrosir.toString())),
  197.                                   enabled: false,
  198.                                   decoration: InputDecoration(
  199.                                     border: OutlineInputBorder(),
  200.                                   ),
  201.                                 ),
  202.                           ),
  203.                          
  204.                           Padding(
  205.                                         padding: EdgeInsets.only(left: 10.0,top: 10.0),
  206.                                         child : Text('Harga Partai',),
  207.                           ),
  208.                           Container(
  209.                               padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
  210.                               height: 30.0,
  211.                                   child : TextFormField(
  212.                                   keyboardType: TextInputType.text,
  213.                                   initialValue: formatCur(double.parse(detailbarang.data[0].hargapartai.toString())),
  214.                                   enabled: false,
  215.                                   decoration: InputDecoration(
  216.                                     border: OutlineInputBorder(),
  217.                                   ),
  218.                                 ),
  219.                           ),
  220.                             Row(
  221.                               children  : <Widget>[
  222.  
  223.                                             Expanded(
  224.                                              
  225.                                               child : Container(
  226.                                                         padding: EdgeInsets.only(left: 10.0,right: 10.0,top: 10.0),
  227.                                                         child   : ButtonTheme(
  228.                                                                   minWidth: 200.0,
  229.                                                                   height  : 30.0,
  230.                                                                   child   : RaisedButton(
  231.                                                                               color: Colors.black,
  232.                                                                               highlightColor: Colors.amberAccent[700],
  233.                                                                               onPressed: () {
  234.                                                                              
  235.                                                                                 },
  236.                                                                   child: Text("Simpan",style: TextStyle(color: Colors.white),),
  237.                                                               ),
  238.                                                   ),
  239.                                               )
  240.                                             ),
  241.                                             Expanded(
  242.                                                   child : Container(
  243.                                                         padding: EdgeInsets.only(left: 10.0,right: 10.0,top: 10.0),
  244.                                                           child :ButtonTheme(
  245.                                                             minWidth: 200.0,
  246.                                                             height: 30.0,
  247.                                                             child: RaisedButton(
  248.                                                                         color: Colors.black,
  249.                                                                         highlightColor: Colors.amberAccent[700],
  250.                                                                         onPressed: () {
  251.                                                                        
  252.                                                                           },
  253.                                                             child: Text("Batal",style: TextStyle(color: Colors.white),),
  254.                                                         ),
  255.                                                     )
  256.                                               ),
  257.                                             ),
  258.                               ]
  259.                           )
  260.                     ],
  261.             )
  262.         )
  263.       );
  264.    
  265.     }
  266.   }
  267.  
  268.   String formatCur(double nilai){
  269.     FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
  270.               amount: nilai
  271.           );
  272.     return fmf.output.withoutFractionDigits;
  273.   }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement