Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'barang_model.dart';
- import 'package:flutter_money_formatter/flutter_money_formatter.dart';
- class DetailBarangPage extends StatefulWidget {
- final String kodebarang;
- const DetailBarangPage(this.kodebarang);
- @override
- _DetailBarangPageState createState() => _DetailBarangPageState();
- }
- class _DetailBarangPageState extends State<DetailBarangPage> {
- DataBarang detailbarang;
- String _kodebarang;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar : AppBar(
- title : Text('Data Barang')
- ),
- body: _buildFieldBarang(),
- );
- }
- void ambilData() async {
- final barang = await ApiService().getData(_kodebarang);
- setState((){
- detailbarang = barang;
- });
- }
- Widget _buildFieldBarang() {
- _kodebarang = widget.kodebarang;
- ambilData();
- if (detailbarang == null) {
- return Center(child: CircularProgressIndicator());
- } else {
- return Container(
- child :SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Kode Barang',style: TextStyle(fontSize: 16.0),),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].kodebarang.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Nama Barang',style: TextStyle(fontSize: 16.0),),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].namabarang.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Kategori',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].namakategori.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- )
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Satuan Beli',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].satuanbeli.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Isi',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].isiperbox.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Satuan Jual',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: detailbarang.data[0].satuanjual.toString(),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Harga Beli',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: formatCur(double.parse(detailbarang.data[0].hargabeli.toString())),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Harga Ecer',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: formatCur(double.parse(detailbarang.data[0].hargaecer.toString())),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Harga Grosir',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: formatCur(double.parse(detailbarang.data[0].hargagrosir.toString())),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 10.0,top: 10.0),
- child : Text('Harga Partai',),
- ),
- Container(
- padding: EdgeInsets.only(left:10.0,right:10.0,top : 5.0),
- height: 30.0,
- child : TextFormField(
- keyboardType: TextInputType.text,
- initialValue: formatCur(double.parse(detailbarang.data[0].hargapartai.toString())),
- enabled: false,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Row(
- children : <Widget>[
- Expanded(
- child : Container(
- padding: EdgeInsets.only(left: 10.0,right: 10.0,top: 10.0),
- child : ButtonTheme(
- minWidth: 200.0,
- height : 30.0,
- child : RaisedButton(
- color: Colors.black,
- highlightColor: Colors.amberAccent[700],
- onPressed: () {
- },
- child: Text("Simpan",style: TextStyle(color: Colors.white),),
- ),
- ),
- )
- ),
- Expanded(
- child : Container(
- padding: EdgeInsets.only(left: 10.0,right: 10.0,top: 10.0),
- child :ButtonTheme(
- minWidth: 200.0,
- height: 30.0,
- child: RaisedButton(
- color: Colors.black,
- highlightColor: Colors.amberAccent[700],
- onPressed: () {
- },
- child: Text("Batal",style: TextStyle(color: Colors.white),),
- ),
- )
- ),
- ),
- ]
- )
- ],
- )
- )
- );
- }
- }
- String formatCur(double nilai){
- FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
- amount: nilai
- );
- return fmf.output.withoutFractionDigits;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement