From 9bd0b1a505b4f47c4f6afe94b9b708c2bf67e257 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Dec 2023 13:57:08 +0700 Subject: [PATCH] perbaikan bug list peti, penambahan refresh page home --- lib/pages/home/home_page.dart | 173 +++++++++++------- .../peminjaman_barang/create-finish.dart | 92 +++++----- .../pengembalian_barang/edit-finish.dart | 92 +++++----- lib/pages/transfer_peti/edit-finish.dart | 92 +++++----- lib/pages/transfer_peti/index.dart | 46 +++-- 5 files changed, 263 insertions(+), 232 deletions(-) diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index c8dd049..3f331e4 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -78,7 +78,15 @@ class _HomePageState extends State { }); } - Future.wait([ + // Memanggil _refreshPage untuk menginisialisasi dan memuat data + _refreshPage(); + + _data = []; + } + + Future _refreshPage() async { + // Menggunakan Future.wait untuk menunggu hasil dari semua tugas selesai + await Future.wait([ _initData(), warehouseListAPI(), typePetiListAPI(), @@ -90,15 +98,14 @@ class _HomePageState extends State { datatablesCustomerList(), datatablesWarehouseList(), initializeDateFormatting('id_ID', null), - ]).then((_) { - // Mengatur _isLoading ke false setelah semua tugas selesai - if (mounted) { - setState(() { - _isLoading = false; - }); - } - }); - _data = []; + ]); + + // Mengatur _isLoading ke false setelah semua tugas selesai + if (mounted) { + setState(() { + _isLoading = false; + }); + } } @override @@ -895,77 +902,101 @@ class _HomePageState extends State { ); } - return AbsorbPointer( - absorbing: _isFetchingData, - child: Scaffold( - backgroundColor: Colors.grey[200], - appBar: AppBar( - elevation: 0, - automaticallyImplyLeading: false, - backgroundColor: Colors.indigo[700], - centerTitle: true, - title: Row( - children: [ - SizedBox(width: 10), - Expanded( - child: Center( - child: Column( - children: [ - Text( - 'SIOPAS-ISTW', - textAlign: TextAlign.center, - ), - Text( - '${user.fullname}', - style: TextStyle( - fontSize: 10, - ), - ), - ], - ), - ), - ), - ], - ), - ), - body: ListView( - children: [ - cardMenuSync(), - SizedBox(height: 10), - Container( - padding: EdgeInsets.all(10), - child: Text( - 'Menu Aplikasi', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + return WillPopScope( + onWillPop: () async { + // Mencegah kembali ke halaman sebelumnya + return false; + }, + child: AbsorbPointer( + absorbing: _isFetchingData, + child: Scaffold( + backgroundColor: Colors.grey[200], + appBar: AppBar( + elevation: 0, + automaticallyImplyLeading: false, + backgroundColor: Colors.indigo[700], + centerTitle: true, + title: Row( children: [ + SizedBox(width: 10), Expanded( - child: cardMenuPeminjaman(), - ), - Expanded( - child: cardMenuPengembalian(), + child: Center( + child: Column( + children: [ + Text( + 'SIOPAS-ISTW', + textAlign: TextAlign.center, + ), + Text( + '${user.fullname}', + style: TextStyle( + fontSize: 10, + ), + ), + ], + ), + ), ), ], ), - SizedBox(height: 10), // Add some space between rows - Row( + ), + body: RefreshIndicator( + color: Colors.white, + backgroundColor: Colors.indigo[700], + onRefresh: () async { + // Tampilkan Shimmer loading selama proses refresh + setState(() { + _isLoading = true; + }); + + // Selesaikan proses refresh + await _refreshPage(); + + // Sembunyikan Shimmer loading setelah selesai + setState(() { + _isLoading = false; + }); + }, + child: ListView( children: [ - Expanded( - child: cardMenuTransfer(), + cardMenuSync(), + SizedBox(height: 10), + Container( + padding: EdgeInsets.all(10), + child: Text( + 'Menu Aplikasi', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), ), - Expanded( - child: Container(), - // child: cardMenuPengembalian(), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: cardMenuPeminjaman(), + ), + Expanded( + child: cardMenuPengembalian(), + ), + ], + ), + SizedBox(height: 10), // Add some space between rows + Row( + children: [ + Expanded( + child: cardMenuTransfer(), + ), + Expanded( + child: Container(), + // child: cardMenuPengembalian(), + ), + ], ), ], ), - ], + ), ), ), ); diff --git a/lib/pages/peminjaman_barang/create-finish.dart b/lib/pages/peminjaman_barang/create-finish.dart index dff92c6..241857b 100644 --- a/lib/pages/peminjaman_barang/create-finish.dart +++ b/lib/pages/peminjaman_barang/create-finish.dart @@ -414,58 +414,56 @@ class _CreateFinishPeminjamanState extends State { color: Colors.grey[100], ), padding: EdgeInsets.all(8), - child: Expanded( - child: ListView.builder( - itemCount: widget.temporaryDataList.length, - itemBuilder: (context, index) { - int? petiId = - widget.temporaryDataList[index].peti_id; - PetiAssetModel? petiSqfliteApi = - _valpeti?.firstWhereOrNull( - (peti) => peti.id == petiId, - ); - - return ConstrainedBox( - constraints: BoxConstraints( - maxHeight: - 100, // Set your desired height here - ), - child: Card( - elevation: 1, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: BorderSide( - color: Colors.grey.withOpacity(0.5), - width: 1, - ), + child: ListView.builder( + itemCount: widget.temporaryDataList.length, + itemBuilder: (context, index) { + int? petiId = + widget.temporaryDataList[index].peti_id; + PetiAssetModel? petiSqfliteApi = + _valpeti?.firstWhereOrNull( + (peti) => peti.id == petiId, + ); + + return ConstrainedBox( + constraints: BoxConstraints( + maxHeight: + 100, // Set your desired height here + ), + child: Card( + elevation: 1, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: Colors.grey.withOpacity(0.5), + width: 1, ), - margin: EdgeInsets.symmetric(vertical: 4), - child: Padding( - padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - child: Row( - children: [ - Text( - '${index + 1}.', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(width: 16), - Text( - ' ${petiSqfliteApi?.fix_lot ?? ''}', - style: TextStyle(fontSize: 13), + ), + margin: EdgeInsets.symmetric(vertical: 4), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Row( + children: [ + Text( + '${index + 1}.', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, ), - // Tambahkan properti lainnya sesuai kebutuhan - ], - ), + ), + SizedBox(width: 16), + Text( + ' ${petiSqfliteApi?.fix_lot ?? ''}', + style: TextStyle(fontSize: 13), + ), + // Tambahkan properti lainnya sesuai kebutuhan + ], ), ), ), - ); - }, - ), + ), + ); + }, ), ), SizedBox(height: 16), diff --git a/lib/pages/pengembalian_barang/edit-finish.dart b/lib/pages/pengembalian_barang/edit-finish.dart index 931730f..31bc00e 100644 --- a/lib/pages/pengembalian_barang/edit-finish.dart +++ b/lib/pages/pengembalian_barang/edit-finish.dart @@ -397,58 +397,56 @@ class _EditFinishPengembalianState extends State { color: Colors.grey[100], ), padding: EdgeInsets.all(8), - child: Expanded( - child: ListView.builder( - itemCount: widget.temporaryDataList.length, - itemBuilder: (context, index) { - int? petiId = - widget.temporaryDataList[index].peti_id; - PetiAssetModel? petiSqfliteApi = - _valpeti?.firstWhereOrNull( - (peti) => peti.id == petiId, - ); - - return ConstrainedBox( - constraints: BoxConstraints( - maxHeight: - 100, // Set your desired height here - ), - child: Card( - elevation: 1, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: BorderSide( - color: Colors.grey.withOpacity(0.5), - width: 1, - ), + child: ListView.builder( + itemCount: widget.temporaryDataList.length, + itemBuilder: (context, index) { + int? petiId = + widget.temporaryDataList[index].peti_id; + PetiAssetModel? petiSqfliteApi = + _valpeti?.firstWhereOrNull( + (peti) => peti.id == petiId, + ); + + return ConstrainedBox( + constraints: BoxConstraints( + maxHeight: + 100, // Set your desired height here + ), + child: Card( + elevation: 1, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: Colors.grey.withOpacity(0.5), + width: 1, ), - margin: EdgeInsets.symmetric(vertical: 4), - child: Padding( - padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - child: Row( - children: [ - Text( - '${index + 1}.', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(width: 16), - Text( - ' ${petiSqfliteApi?.fix_lot ?? ''}', - style: TextStyle(fontSize: 13), + ), + margin: EdgeInsets.symmetric(vertical: 4), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Row( + children: [ + Text( + '${index + 1}.', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, ), - // Tambahkan properti lainnya sesuai kebutuhan - ], - ), + ), + SizedBox(width: 16), + Text( + ' ${petiSqfliteApi?.fix_lot ?? ''}', + style: TextStyle(fontSize: 13), + ), + // Tambahkan properti lainnya sesuai kebutuhan + ], ), ), ), - ); - }, - ), + ), + ); + }, ), ), SizedBox(height: 16), diff --git a/lib/pages/transfer_peti/edit-finish.dart b/lib/pages/transfer_peti/edit-finish.dart index d6f8c60..1c0212f 100644 --- a/lib/pages/transfer_peti/edit-finish.dart +++ b/lib/pages/transfer_peti/edit-finish.dart @@ -415,58 +415,56 @@ class _EditFinishTransferPetiState extends State { color: Colors.grey[100], ), padding: EdgeInsets.all(8), - child: Expanded( - child: ListView.builder( - itemCount: widget.temporaryDataList.length, - itemBuilder: (context, index) { - int? petiId = - widget.temporaryDataList[index].peti_id; - PetiAssetModel? petiSqfliteApi = - _valpeti?.firstWhereOrNull( - (peti) => peti.id == petiId, - ); - - return ConstrainedBox( - constraints: BoxConstraints( - maxHeight: - 100, // Set your desired height here - ), - child: Card( - elevation: 1, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: BorderSide( - color: Colors.grey.withOpacity(0.5), - width: 1, - ), + child: ListView.builder( + itemCount: widget.temporaryDataList.length, + itemBuilder: (context, index) { + int? petiId = + widget.temporaryDataList[index].peti_id; + PetiAssetModel? petiSqfliteApi = + _valpeti?.firstWhereOrNull( + (peti) => peti.id == petiId, + ); + + return ConstrainedBox( + constraints: BoxConstraints( + maxHeight: + 100, // Set your desired height here + ), + child: Card( + elevation: 1, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: Colors.grey.withOpacity(0.5), + width: 1, ), - margin: EdgeInsets.symmetric(vertical: 4), - child: Padding( - padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - child: Row( - children: [ - Text( - '${index + 1}.', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(width: 16), - Text( - ' ${petiSqfliteApi?.fix_lot ?? ''}', - style: TextStyle(fontSize: 13), + ), + margin: EdgeInsets.symmetric(vertical: 4), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Row( + children: [ + Text( + '${index + 1}.', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, ), - // Tambahkan properti lainnya sesuai kebutuhan - ], - ), + ), + SizedBox(width: 16), + Text( + ' ${petiSqfliteApi?.fix_lot ?? ''}', + style: TextStyle(fontSize: 13), + ), + // Tambahkan properti lainnya sesuai kebutuhan + ], ), ), ), - ); - }, - ), + ), + ); + }, ), ), SizedBox(height: 16), diff --git a/lib/pages/transfer_peti/index.dart b/lib/pages/transfer_peti/index.dart index 90ae034..a9fbe70 100644 --- a/lib/pages/transfer_peti/index.dart +++ b/lib/pages/transfer_peti/index.dart @@ -249,27 +249,33 @@ class TransferPetiPageState extends State { @override Widget build(BuildContext context) { - return DefaultTabController( - length: 1, - child: Scaffold( - appBar: appBar(context), - body: _isLoading - ? Column( - children: [ - // shimmerSearch(), - Expanded( - child: ListView.builder( - itemCount: - 4, // Set the number of shimmer cards based on your data count - itemBuilder: (context, index) { - return ShimmerLoadingAssetStatusCard(); - }, + return WillPopScope( + onWillPop: () async { + // Mencegah kembali ke halaman sebelumnya + return false; + }, + child: DefaultTabController( + length: 1, + child: Scaffold( + appBar: appBar(context), + body: _isLoading + ? Column( + children: [ + // shimmerSearch(), + Expanded( + child: ListView.builder( + itemCount: + 4, // Set the number of shimmer cards based on your data count + itemBuilder: (context, index) { + return ShimmerLoadingAssetStatusCard(); + }, + ), ), - ), - ], - ) - : bodyTransferPeti(), - bottomNavigationBar: bottomAppBar(context), + ], + ) + : bodyTransferPeti(), + bottomNavigationBar: bottomAppBar(context), + ), ), ); }