0% found this document useful (0 votes)
23 views3 pages

Datatable Dart

The document shows code for a Flutter app that displays a list of product data in a data table. It imports necessary packages, defines classes for the app and data, and builds the UI with a data table to display the product list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Datatable Dart

The document shows code for a Flutter app that displays a list of product data in a data table. It imports necessary packages, defines classes for the app and data, and builds the UI with a data table to display the product list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import 'package:flutter/material.

dart';

void main() {
runApp(MaterialApp(home: AinunAlwiHarahap()));
}

class AinunAlwiHarahap extends StatefulWidget {


_AinunAlwiHarahapState createState() => _AinunAlwiHarahapState();
}

class _AinunAlwiHarahapState extends State<AinunAlwiHarahap> {


// Deklarasi List
List<DataBarang> databarang;
void initState() {
super.initState();
databarang = DataBarang.getDataBarang();
}

Widget build(BuildContext context) {


return Scaffold(
appBar: AppBar(
title: Text('Ainun Alwi Harahap - 2019020432'),
),
body: ListView(children: <Widget>[
Center(
child: Text('Data Barang Masuk',
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold))),
DataTable(
columns: [
DataColumn(
label: Text('Kode Barang',
style:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('Nama Barang',
style:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('Harga',
style:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('Jumlah Stok',
style:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold))),
],
rows: DataBarang.getDataBarang()
.map(
(databarang) => DataRow(cells: [
DataCell(Text(databarang.kodeBarang)),
DataCell(Text(databarang.namaBarang)),
DataCell(Text(databarang.harga)),
DataCell(Text(databarang.jumlahStok)),
]),
)
.toList(),
),
]),
);
}
}

class DataBarang {
//Attribut
String kodeBarang;
String namaBarang;
String harga;
String jumlahStok;

//Constructor
DataBarang({this.kodeBarang, this.namaBarang, this.harga, this.jumlahStok});

//Data List
static List<DataBarang> getDataBarang() {
return <DataBarang>[
DataBarang(
kodeBarang: "BR001",
namaBarang: "Indomie Goreng",
harga: "Rp.3000",
jumlahStok: "100"),
DataBarang(
kodeBarang: "BR002",
namaBarang: "Sabun Mandi",
harga: "Rp. 2000",
jumlahStok: "55"),
DataBarang(
kodeBarang: "BR003",
namaBarang: "Sikat Gigi",
harga: "Rp. 5000",
jumlahStok: "20"),
DataBarang(
kodeBarang: "BR004",
namaBarang: "Susu Coklat",
harga: "Rp.15000",
jumlahStok: "10"),
DataBarang(
kodeBarang: "BR005",
namaBarang: "Kripik Ubi",
harga: "Rp. 5000",
jumlahStok: "35"),
DataBarang(
kodeBarang: "BR006",
namaBarang: "Minuman Kaleng",
harga: "Rp. 7000",
jumlahStok: "200"),
DataBarang(
kodeBarang: "BR007",
namaBarang: "Celengan Ayam",
harga: "Rp.2000",
jumlahStok: "12"),
DataBarang(
kodeBarang: "BR008",
namaBarang: "Sepatu Sekolah",
harga: "Rp. 35000",
jumlahStok: "24"),
DataBarang(
kodeBarang: "BR009",
namaBarang: "Gas Elpiji 3Kg",
harga: "Rp. 18000",
jumlahStok: "30"),
DataBarang(
kodeBarang: "BR0010",
namaBarang: "Minyak Sachet 2L",
harga: "Rp. 28000",
jumlahStok: "40"),
];
}
}

You might also like