Advertisement
Guest User

stikiheader

a guest
Jan 20th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 25.72 KB | None | 0 0
  1.  
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_money_formatter/flutter_money_formatter.dart';
  5. import 'package:pull_to_refresh/pull_to_refresh.dart';
  6. import 'package:expandable/expandable.dart';
  7. import 'package:semesta_listrik/ladingpage/appdrawer.dart';
  8. import 'package:semesta_listrik/penjualan/penjualan_model.dart';
  9. import 'package:sticky_headers/sticky_headers.dart';
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. class PenjualanDataPage extends StatefulWidget {
  17.   PenjualanDataPage({Key key}) : super(key: key);
  18.  
  19.   @override
  20.   _PenjualanDatarPageState createState() => _PenjualanDatarPageState();
  21. }
  22.  
  23. class _PenjualanDatarPageState extends State<PenjualanDataPage> {
  24.  
  25.   ApiService apiService;
  26.   PenjualanData _penjualanData ;
  27.   Widget appBarTitle  = Text("Cari Pelanggan",style: TextStyle(color: Colors.white),);
  28.   Icon icon           = Icon(Icons.search, color: Colors.white,);
  29.   final TextEditingController _controller = TextEditingController();
  30.   RefreshController _refreshController = RefreshController(initialRefresh: false);
  31.  
  32.   bool _isSearching   = false;
  33.  
  34.   String tgl1;
  35.   String tgl2;
  36.   String pelanggan          = "";
  37.   String kodepelanggan ="";
  38.  
  39.  
  40.  
  41.   @override
  42.   void initState() {
  43.     super.initState();
  44.  
  45.     var now = DateTime.now();
  46.     var lastDayDateTime = (now.month < 12) ?  DateTime(now.year, now.month + 1, 0) : DateTime(now.year + 1, 1, 0);
  47.     tgl1   = (now.year).toString()+'-'+(now.month).toString()+'-1';
  48.     tgl2   = (now.year).toString()+'-'+(now.month).toString()+'-'+lastDayDateTime.day.toString();
  49.     pelanggan = "";
  50.    
  51.     ambilData();
  52.    // ambilDetail(kodepelanggan);
  53.   }
  54.  
  55.   void _onRefresh() async {
  56.       await Future.delayed(Duration(microseconds: 500));
  57.      final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
  58.       setState((){
  59.         _penjualanData = datas;
  60.       });
  61.  
  62.     _refreshController.refreshCompleted();
  63.   }
  64.  
  65.   void ambilData() async {
  66.   final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
  67.    setState((){
  68.      _penjualanData = datas;
  69.    
  70.    });
  71.    _refreshController.loadComplete();
  72.   }
  73.  
  74.  
  75.  void cariData(String pelanggan) async {
  76.   final datas = await ApiService().getData(tgl1,tgl2,pelanggan);
  77.    setState((){    
  78.      _penjualanData = datas;
  79.    });
  80.   }
  81.  
  82.  
  83.  
  84.   @override
  85.   Widget build(BuildContext context) {
  86.    return Scaffold(
  87.       appBar: _buildAppBar(context),
  88.       body: ListView(
  89.             children: <Widget>[
  90.               StickyHeader(
  91.                 header: _headerSticky(),
  92.                 content: _buildData(),
  93.               )
  94.             ],
  95.       ),
  96.      );
  97.  
  98.   }
  99.  
  100.   Widget _headerSticky(){
  101.     return Container(
  102.                         height: 80.0,
  103.                         width: MediaQuery.of(context).size.width,
  104.                         decoration:  BoxDecoration(
  105.                           color: Colors.amberAccent[700],
  106.                         borderRadius:  BorderRadius.circular(5.0),
  107.                         border: Border.all(
  108.                           width: 1.0,
  109.                           color: Colors.transparent,
  110.                         ),
  111.                       ),
  112.                      
  113.                                     padding: EdgeInsets.all(5.0),
  114.  
  115.                                     child :Row(
  116.                                         crossAxisAlignment: CrossAxisAlignment.start,
  117.                                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  118.                                         children: <Widget>[
  119.                                         Expanded(
  120.                                             child :Container(
  121.                                                   child :Column(
  122.                                                     crossAxisAlignment: CrossAxisAlignment.start,
  123.                                                   children : <Widget>[
  124.                                                     Row(
  125.                                                       children : <Widget>[
  126.                                                             Padding(
  127.                                                               padding : EdgeInsets.only(left : 10.0,top: 5.0,right: 5.0),
  128.                                                               child:  Icon(Icons.date_range,size: 14.0,color: Colors.black,)
  129.                                                               ),
  130.                                                             Padding(
  131.                                                               padding : EdgeInsets.only(top: 5.0,right: 5.0),
  132.                                                               child:  Text('Dari Tgl',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
  133.                                                             ),
  134.                                                       ]),
  135.                                                         Container(
  136.                                                           height: 30.0,
  137.                                                                   padding : EdgeInsets.only(left : 10.0,right: 5.0,top:5.0),
  138.                                                                   child:  TextFormField(
  139.                                                                           keyboardType: TextInputType.text,
  140.                                                                           enabled: true,
  141.                                                                           decoration: InputDecoration(
  142.                                                                             border: OutlineInputBorder(),
  143.                                                                       ),
  144.                                                                   )
  145.                                                               ),
  146.                                                        
  147.  
  148.                                                   ]),
  149.                                               )
  150.                                             ),
  151.                                           Expanded(
  152.                                             child :Container(
  153.                                                   child :Column(
  154.                                                     crossAxisAlignment: CrossAxisAlignment.start,
  155.                                             children : <Widget>[                                    
  156.                                                       Row(
  157.                                                       children : <Widget>[
  158.                                                             Padding(
  159.                                                             padding : EdgeInsets.only(left : 5.0,top: 5.0,),
  160.                                                             child:  Icon(Icons.insert_invitation,size: 14.0,color: Colors.black,),
  161.                                                            
  162.                                                           ),
  163.                                                      
  164.                                                       Padding(
  165.                                                                   padding : EdgeInsets.only(top: 5.0,right: 5.0,left: 5.0),
  166.                                                                   child:  Text('Sampai Tgl',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
  167.                                                                
  168.                                                       ),
  169.                                                       ]
  170.                                                       ),
  171.                                                       Container(
  172.                                                           height: 30.0,
  173.                                                                   padding : EdgeInsets.only(left : 10.0,right: 5.0,top: 5.0),
  174.                                                                   child:  TextFormField(
  175.                                                                           keyboardType: TextInputType.text,
  176.                                                                           enabled: true,
  177.                                                                           decoration: InputDecoration(
  178.                                                                             border: OutlineInputBorder(),
  179.                                                                       ),
  180.                                                                   )
  181.                                                                
  182.                                                       ),
  183.                                             ]),
  184.                                             )
  185.                                           ),
  186.                                           Expanded(
  187.                                             child : Container(
  188.                                               padding: EdgeInsets.only(top: 15.0,right: 10.0),
  189.                                               width: 20.0,
  190.                                             child :ButtonTheme(                                            
  191.                                                             minWidth: 20.0,
  192.                                                             height: 30.0,
  193.                                                             child: RaisedButton(
  194.                                                                         color: Colors.black,
  195.                                                                         highlightColor: Colors.amberAccent[700],
  196.                                                                         onPressed: () {Navigator.pop(context);
  197.                                                                        
  198.                                                                           },
  199.                                                             child: Text("Filter",style: TextStyle(color: Colors.amberAccent[700]),),
  200.                                                         ),
  201.                                                     )
  202.                                           )
  203.                                           )
  204.  
  205.                                         ],
  206.                                       ),
  207.                                   );
  208.                              
  209.   }
  210.  
  211.    Widget _buildData(){
  212.      if (_penjualanData == null){
  213.         return Container(child: Center(child: Text('No data display'),),);
  214.      } else {
  215.           return ListView.builder(
  216.                                 shrinkWrap: true,
  217.                                 itemCount: _penjualanData.data.length,
  218.                                 physics: ClampingScrollPhysics(),
  219.                                 itemBuilder: (BuildContext context,int index){
  220.                                   final nobukti       = _penjualanData.data[index].nobukti.toString();
  221.                                   final namapelanggan = _penjualanData.data[index].namapelanggan.toString();
  222.                                   final tgl           = _penjualanData.data[index].tgl.toString();
  223.                                   final kasir         = _penjualanData.data[index].kasir.toString();
  224.                                   final grandtotal    = _penjualanData.data[index].grandtotal.toString();
  225.                                   return Card(
  226.                                     child :Column(
  227.                                     children: <Widget>[
  228.                                       Card(
  229.                                         color : Colors.amberAccent[700],
  230.                                         child : Column(
  231.                                           mainAxisAlignment: MainAxisAlignment.start,
  232.                                           crossAxisAlignment: CrossAxisAlignment.start,
  233.                                           children : <Widget> [
  234.                                                   Padding(
  235.                                                     padding: EdgeInsets.all(10.0),
  236.                                                     child: Text(nobukti+' [ '+kasir+' ]',style: TextStyle(fontSize: 14.0,color: Colors.black,fontWeight: FontWeight.bold),),
  237.                                                   ),
  238.                                                   Divider(color: Colors.white60,height: 10.0,),
  239.                                                     Row(
  240.                                                       children: <Widget>[
  241.                                                         Padding(
  242.                                                           padding : EdgeInsets.only(left : 5.0,top: 5.0,right: 5.0),
  243.                                                           child:  Icon(Icons.account_box,size: 14.0,color: Colors.black,)
  244.                                                         ),                                    
  245.                                                         Expanded(
  246.                                                             child : Padding(
  247.                                                                     padding : EdgeInsets.only(top: 5.0,right: 5.0),
  248.                                                                     child:  Text('Cust',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
  249.                                                                   ),
  250.                                                         ),
  251.                                                         Padding(
  252.                                                           padding : EdgeInsets.only(left : 5.0,top: 5.0,),
  253.                                                           child:  Icon(Icons.attach_money,size: 14.0,color: Colors.black,),
  254.                                                         ),
  255.                                                        
  256.                                                         Expanded(
  257.                                                             child : Padding(
  258.                                                                     padding : EdgeInsets.only(top: 5.0,right: 5.0),
  259.                                                                     child:  Text('Total',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
  260.                                                                   ),
  261.                                                        
  262.                                                         ),
  263.                                                         Padding(
  264.                                                           padding : EdgeInsets.only(left : 5.0,top: 5.0,),
  265.                                                           child:  Icon(Icons.attach_money,size: 14.0,color: Colors.black,),
  266.                                                         ),
  267.                                                         Expanded(
  268.                                                             child : Padding(
  269.                                                                     padding : EdgeInsets.only(top: 5.0,right: 5.0),
  270.                                                                     child:  Text('Tanggal',style: TextStyle(fontSize: 12.0,color: Colors.black,),)
  271.                                                                   ),
  272.                                                         ),
  273.                                                        
  274.                                                        
  275.                                                      
  276.  
  277.                                                       ],
  278.                                                     ),
  279.                                                    
  280.                                                     Row(
  281.                                                       children: <Widget>[
  282.                                                        
  283.                                                         Expanded(
  284.                                                          
  285.                                                             child :  Padding(
  286.                                                               padding : EdgeInsets.only(left : 25.0,top: 10.0,right: 10.0,bottom: 10.0),
  287.                                                               child: Text(namapelanggan,style: TextStyle(fontSize: 10.0,color: Colors.black,),),
  288.                                                               ),
  289.                                                            
  290.                                                         ),
  291.                                                         Expanded(
  292.                                                          
  293.                                                             child :  Padding(
  294.                                                               padding : EdgeInsets.only(left : 15.0,top: 10.0,right: 10.0,bottom: 10.0),
  295.                                                               child: Text(formatCur(double.parse(grandtotal)),style: TextStyle(fontSize: 10.0,color: Colors.black,),),
  296.                                                               ),
  297.                                                            
  298.                                                        
  299.                                                         ),
  300.                                                         Expanded(
  301.                                                             child :  Padding(
  302.                                                               padding : EdgeInsets.only(left : 20.0,top: 10.0,right: 10.0,bottom: 10.0),
  303.                                                               child: Text(tgl,style: TextStyle(fontSize: 10.0,color: Colors.black,),)
  304.                                                             )
  305.                                                         ),
  306.  
  307.                                                       ],
  308.                                                     )
  309.                                           ]
  310.                                         )
  311.                                       ),
  312.                                       ExpandableNotifier(
  313.                                             child :ScrollOnExpand(
  314.                                                 child: Card(
  315.                                                   clipBehavior: Clip.antiAlias,
  316.                                                   child: Column(
  317.                                                     crossAxisAlignment: CrossAxisAlignment.start,
  318.                                                     children: <Widget>[
  319.                                                    
  320.                                                      
  321.                                                         Expandable(
  322.                                                         collapsed: buildCollapsed3(),
  323.                                                         expanded: buildExpanded3(_penjualanData.data[index].detail),
  324.                                                      
  325.                                                       ),
  326.                                                      
  327.                                                       Row(
  328.                                                         mainAxisAlignment: MainAxisAlignment.start,
  329.                                                         children: <Widget>[
  330.                                                           Builder(
  331.                                                             builder: (context) {
  332.                                                               var controller = ExpandableController.of(context);
  333.                                                               return FlatButton(
  334.                                                                 child: Text(controller.expanded ? "Tutup": "Lihat Detail",
  335.                                                                   style: Theme.of(context).textTheme.button.copyWith(
  336.                                                                     color: Colors.redAccent[700]
  337.                                                                   ),
  338.                                                                 ),
  339.                                                                 onPressed: () {
  340.                                                                   controller.toggle();
  341.                                                                 },
  342.                                                               );
  343.                                                             },
  344.                                                           ),
  345.                                                         ],
  346.                                                       ),
  347.                                                     ],
  348.                                                   )
  349.                                                 )
  350.                                               )
  351.                                            
  352.                                           )
  353.                                     ],
  354.                                    
  355.                                   ),
  356.                                  
  357.                               );
  358.                             },
  359.                  
  360.                           );
  361.      }
  362.  
  363.    }
  364.     buildCollapsed3() {
  365.       return Container();
  366.     }
  367.  
  368.    
  369.  
  370.     buildExpanded3(List<Detail> _list) {
  371.      
  372.           return   Column(
  373.                           children : <Widget> [
  374.                        
  375.                                   SingleChildScrollView(
  376.                                     scrollDirection: Axis.horizontal,
  377.                                       child :Container(
  378.                                        
  379.                                         child  : DataTable(
  380.                                         headingRowHeight: 30.0,  
  381.                                         horizontalMargin:3.0,
  382.                                         columnSpacing: 0.0,
  383.                                         dataRowHeight: 25.0,
  384.  
  385.                                           columns: [
  386.                                  
  387.                                             DataColumn(
  388.                                               label: Text('Kode Barang',style: TextStyle(fontSize: 12.0, color: Colors.black),)),
  389.                                             DataColumn(label: Text('Nama Barang',style: TextStyle(fontSize: 12.0,color: Colors.black),)),
  390.                                             DataColumn(label: Text('Jumlah',style: TextStyle(fontSize: 12.0,color: Colors.black),),
  391.                                                     numeric: true,),
  392.                                             DataColumn(label: Text('Harga',style: TextStyle(fontSize: 12.0,color: Colors.black),),
  393.                                                     numeric: true),
  394.                                             DataColumn(label: Text('Subtotal',style: TextStyle(fontSize: 12.0,color: Colors.black),),
  395.                                                     numeric: true),
  396.                                           ],
  397.                                           rows: _list.map((Detail detail)=> DataRow(
  398.                                             selected: true,
  399.                                             cells: [
  400.                                               DataCell(Text(detail.kodebarang,style: TextStyle(fontSize: 9.0,),),),
  401.                                               DataCell(Text(detail.namabarang,style: TextStyle(fontSize: 9.0,),)),
  402.                                               DataCell(Text(formatCur(double.parse(detail.jumlah)),style: TextStyle(fontSize: 9.0,),)),
  403.                                               DataCell(Text(formatCur(double.parse(detail.harga)),style: TextStyle(fontSize: 9.0,),)),
  404.                                               DataCell(Text(formatCur(double.parse(detail.subtotal)),style: TextStyle(fontSize: 9.0,),)),
  405.                                             ]
  406.                                           )
  407.                                           ).toList() ,
  408.                                         )
  409.                                     ),
  410.                                   )
  411.                           ]);
  412.      
  413.     }
  414.   Widget _buildAppBar(BuildContext context){
  415.     return AppBar(
  416.       centerTitle: true,
  417.       title: appBarTitle,
  418.       actions: <Widget>[
  419.         IconButton(
  420.           icon: icon,
  421.           onPressed: () {
  422.             setState(() {
  423.               if (this.icon.icon == Icons.search) {
  424.                 this.icon = Icon(Icons.close, color: Colors.white,);
  425.  
  426.                 this.appBarTitle = TextField(
  427.                   controller: _controller,
  428.                   style: TextStyle(color: Colors.white),
  429.                   decoration: InputDecoration(
  430.                     prefixIcon: Icon(Icons.search, color: Colors.white,),
  431.                     hintText: 'Cari pelanggan.. ',
  432.                     hintStyle: TextStyle(color: Colors.white)
  433.                   ),
  434.                   onChanged: searchOperation,
  435.                 );
  436.                 _handleSearchStart();
  437.               } else {
  438.                 _handleSearchEnd();
  439.                
  440.               }
  441.             });
  442.           },)
  443.       ],);
  444.  
  445.   }
  446. void _handleSearchStart() {
  447.     setState(() {
  448.       _isSearching = true;
  449.     });
  450.   }
  451.  
  452.   void _handleSearchEnd() {
  453.     setState(() {
  454.       this.icon = Icon(
  455.         Icons.search,
  456.         color: Colors.white,
  457.       );
  458.       this.appBarTitle = Text(
  459.         "Cari pelanggan",
  460.         style: TextStyle(color: Colors.white),
  461.       );
  462.       _isSearching = false;
  463.       _controller.clear();
  464.      
  465.     });
  466.   }
  467.  
  468.   void searchOperation(String searchText){
  469.     if (_isSearching != null) {
  470.           pelanggan = 'AND pl.namapelanggan LIKE "%'+searchText+'%" ';
  471.          
  472.           cariData(pelanggan);
  473.      
  474.     }
  475.   }
  476.   String formatCur(double nilai){
  477.     FlutterMoneyFormatter fmf = FlutterMoneyFormatter(
  478.               amount: nilai
  479.           );
  480.     return fmf.output.withoutFractionDigits;
  481.   }
  482.  
  483.  
  484.  
  485.  
  486. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement