Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_money_formatter/flutter_money_formatter.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- import 'package:expandable/expandable.dart';
- import 'package:semesta_listrik/ladingpage/appdrawer.dart';
- import 'package:semesta_listrik/penjualan/penjualan_model.dart';
- import 'package:sticky_headers/sticky_headers.dart';
- class PenjualanDataPage extends StatefulWidget {
- PenjualanDataPage({Key key}) : super(key: key);
- @override
- _PenjualanDatarPageState createState() => _PenjualanDatarPageState();
- }
- class _PenjualanDatarPageState extends State<PenjualanDataPage> {
- ApiService apiService;
- PenjualanData _penjualanData ;
- Widget appBarTitle = Text("Cari Pelanggan",style: TextStyle(color: Colors.white),);
- Icon icon = Icon(Icons.search, color: Colors.white,);
- final TextEditingController _controller = TextEditingController();
- RefreshController _refreshController = RefreshController(initialRefresh: false);
- bool _isSearching = false;
- String tgl1;
- String tgl2;
- String pelanggan = "";
- String kodepelanggan ="";
- @override
- void initState() {
- super.initState();
- var now = DateTime.now();
- var lastDayDateTime = (now.month < 12) ? DateTime(now.year, now.month + 1, 0) : DateTime(now.year + 1, 1, 0);
- tgl1 = (now.year).toString()+'-'+(now.month).toString()+'-1';
- tgl2 = (now.year).toString()+'-'+(now.month).toString()+'-'+lastDayDateTime.day.toString();
- pelanggan = "";
- ambilData();
- // ambilDetail(kodepelanggan);
- }
- void _onRefresh() async {
- await Future.delayed(Duration(microseconds: 500));
- final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
- setState((){
- _penjualanData = datas;
- });
- _refreshController.refreshCompleted();
- }
- void ambilData() async {
- final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
- setState((){
- _penjualanData = datas;
- });
- _refreshController.loadComplete();
- }
- void cariData(String pelanggan) async {
- final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
- setState((){
- _penjualanData = datas;
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: _buildAppBar(context),
- body: ListView(
- children: <Widget>[
- StickyHeader(
- header: _headerSticky(),
- content: _buildData(),
- )
- ],
- ),
- );
- }
- Widget _headerSticky(){
- return Container(
- height: 80.0,
- width: MediaQuery.of(context).size.width,
- decoration: BoxDecoration(
- color: Colors.amberAccent[700],
- borderRadius: BorderRadius.circular(5.0),
- border: Border.all(
- width: 1.0,
- color: Colors.transparent,
- ),
- ),
- padding: EdgeInsets.all(5.0),
- child :Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Expanded(
- child :Container(
- child :Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children : <Widget>[
- Row(
- children : <Widget>[
- Padding(
- padding : EdgeInsets.only(left : 10.0,top: 5.0,right: 5.0),
- child: Icon(Icons.date_range,size: 14.0,color: Colors.black,)
- ),
- Padding(
- padding : EdgeInsets.only(top: 5.0,right: 5.0),
- child: Text('Dari Tgl',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
- ),
- ]),
- Container(
- height: 30.0,
- padding : EdgeInsets.only(left : 10.0,right: 5.0,top:5.0),
- child: TextFormField(
- keyboardType: TextInputType.text,
- enabled: true,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- )
- ),
- ]),
- )
- ),
- Expanded(
- child :Container(
- child :Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children : <Widget>[
- Row(
- children : <Widget>[
- Padding(
- padding : EdgeInsets.only(left : 5.0,top: 5.0,),
- child: Icon(Icons.insert_invitation,size: 14.0,color: Colors.black,),
- ),
- Padding(
- padding : EdgeInsets.only(top: 5.0,right: 5.0,left: 5.0),
- child: Text('Sampai Tgl',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
- ),
- ]
- ),
- Container(
- height: 30.0,
- padding : EdgeInsets.only(left : 10.0,right: 5.0,top: 5.0),
- child: TextFormField(
- keyboardType: TextInputType.text,
- enabled: true,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- ),
- )
- ),
- ]),
- )
- ),
- Expanded(
- child : Container(
- padding: EdgeInsets.only(top: 15.0,right: 10.0),
- width: 20.0,
- child :ButtonTheme(
- minWidth: 20.0,
- height: 30.0,
- child: RaisedButton(
- color: Colors.black,
- highlightColor: Colors.amberAccent[700],
- onPressed: () {Navigator.pop(context);
- },
- child: Text("Filter",style: TextStyle(color: Colors.amberAccent[700]),),
- ),
- )
- )
- )
- ],
- ),
- );
- }
- Widget _buildData(){
- if (_penjualanData == null){
- return Container(child: Center(child: Text('No data display'),),);
- } else {
- return ListView.builder(
- shrinkWrap: true,
- itemCount: _penjualanData.data.length,
- physics: ClampingScrollPhysics(),
- itemBuilder: (BuildContext context,int index){
- final nobukti = _penjualanData.data[index].nobukti.toString();
- final namapelanggan = _penjualanData.data[index].namapelanggan.toString();
- final tgl = _penjualanData.data[index].tgl.toString();
- final kasir = _penjualanData.data[index].kasir.toString();
- final grandtotal = _penjualanData.data[index].grandtotal.toString();
- return Card(
- child :Column(
- children: <Widget>[
- Card(
- color : Colors.amberAccent[700],
- child : Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children : <Widget> [
- Padding(
- padding: EdgeInsets.all(10.0),
- child: Text(nobukti+' [ '+kasir+' ]',style: TextStyle(fontSize: 14.0,color: Colors.black,fontWeight: FontWeight.bold),),
- ),
- Divider(color: Colors.white60,height: 10.0,),
- Row(
- children: <Widget>[
- Padding(
- padding : EdgeInsets.only(left : 5.0,top: 5.0,right: 5.0),
- child: Icon(Icons.account_box,size: 14.0,color: Colors.black,)
- ),
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(top: 5.0,right: 5.0),
- child: Text('Cust',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
- ),
- ),
- Padding(
- padding : EdgeInsets.only(left : 5.0,top: 5.0,),
- child: Icon(Icons.attach_money,size: 14.0,color: Colors.black,),
- ),
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(top: 5.0,right: 5.0),
- child: Text('Total',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
- ),
- ),
- Padding(
- padding : EdgeInsets.only(left : 5.0,top: 5.0,),
- child: Icon(Icons.attach_money,size: 14.0,color: Colors.black,),
- ),
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(top: 5.0,right: 5.0),
- child: Text('Tanggal',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
- ),
- ),
- ],
- ),
- Row(
- children: <Widget>[
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(left : 25.0,top: 10.0,right: 10.0,bottom: 10.0),
- child: Text(namapelanggan,style: TextStyle(fontSize: 10.0,color: Colors.black,),),
- ),
- ),
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(left : 15.0,top: 10.0,right: 10.0,bottom: 10.0),
- child: Text(formatCur(double.parse(grandtotal)),style: TextStyle(fontSize: 10.0,color: Colors.black,),),
- ),
- ),
- Expanded(
- child : Padding(
- padding : EdgeInsets.only(left : 20.0,top: 10.0,right: 10.0,bottom: 10.0),
- child: Text(tgl,style: TextStyle(fontSize: 10.0,color: Colors.black,),)
- )
- ),
- ],
- )
- ]
- )
- ),
- ExpandableNotifier(
- child :ScrollOnExpand(
- child: Card(
- clipBehavior: Clip.antiAlias,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Expandable(
- collapsed: buildCollapsed3(),
- expanded: buildExpanded3(_penjualanData.data[index].detail),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Builder(
- builder: (context) {
- var controller = ExpandableController.of(context);
- return FlatButton(
- child: Text(controller.expanded ? "Tutup": "Lihat Detail",
- style: Theme.of(context).textTheme.button.copyWith(
- color: Colors.redAccent[700]
- ),
- ),
- onPressed: () {
- controller.toggle();
- },
- );
- },
- ),
- ],
- ),
- ],
- )
- )
- )
- )
- ],
- ),
- );
- },
- );
- }
- }
- buildCollapsed3() {
- return Container();
- }
- buildExpanded3(List<Detail> _list) {
- return Column(
- children : <Widget> [
- SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- child :Container(
- child : DataTable(
- headingRowHeight: 30.0,
- horizontalMargin:3.0,
- columnSpacing: 0.0,
- dataRowHeight: 25.0,
- columns: [
- DataColumn(
- label: Text('Kode Barang',style: TextStyle(fontSize: 12.0, color: Colors.black),)),
- DataColumn(label: Text('Nama Barang',style: TextStyle(fontSize: 12.0,color: Colors.black),)),
- DataColumn(label: Text('Jumlah',style: TextStyle(fontSize: 12.0,color: Colors.black),),
- numeric: true,),
- DataColumn(label: Text('Harga',style: TextStyle(fontSize: 12.0,color: Colors.black),),
- numeric: true),
- DataColumn(label: Text('Subtotal',style: TextStyle(fontSize: 12.0,color: Colors.black),),
- numeric: true),
- ],
- rows: _list.map((Detail detail)=> DataRow(
- selected: true,
- cells: [
- DataCell(Text(detail.kodebarang,style: TextStyle(fontSize: 9.0,),),),
- DataCell(Text(detail.namabarang,style: TextStyle(fontSize: 9.0,),)),
- DataCell(Text(formatCur(double.parse(detail.jumlah)),style: TextStyle(fontSize: 9.0,),)),
- DataCell(Text(formatCur(double.parse(detail.harga)),style: TextStyle(fontSize: 9.0,),)),
- DataCell(Text(formatCur(double.parse(detail.subtotal)),style: TextStyle(fontSize: 9.0,),)),
- ]
- )
- ).toList() ,
- )
- ),
- )
- ]);
- }
- Widget _buildAppBar(BuildContext context){
- return AppBar(
- centerTitle: true,
- title: appBarTitle,
- actions: <Widget>[
- IconButton(
- icon: icon,
- onPressed: () {
- setState(() {
- if (this.icon.icon == Icons.search) {
- this.icon = Icon(Icons.close, color: Colors.white,);
- this.appBarTitle = TextField(
- controller: _controller,
- style: TextStyle(color: Colors.white),
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.search, color: Colors.white,),
- hintText: 'Cari pelanggan.. ',
- hintStyle: TextStyle(color: Colors.white)
- ),
- onChanged: searchOperation,
- );
- _handleSearchStart();
- } else {
- _handleSearchEnd();
- }
- });
- },)
- ],);
- }
- void _handleSearchStart() {
- setState(() {
- _isSearching = true;
- });
- }
- void _handleSearchEnd() {
- setState(() {
- this.icon = Icon(
- Icons.search,
- color: Colors.white,
- );
- this.appBarTitle = Text(
- "Cari pelanggan",
- style: TextStyle(color: Colors.white),
- );
- _isSearching = false;
- _controller.clear();
- });
- }
- void searchOperation(String searchText){
- if (_isSearching != null) {
- pelanggan = 'AND pl.namapelanggan LIKE "%'+searchText+'%" ';
- cariData(pelanggan);
- }
- }
- String formatCur(double nilai){
- FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
- amount: nilai
- );
- return fmf.output.withoutFractionDigits;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement