You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
7.6 KiB
288 lines
7.6 KiB
1 year ago
|
import 'dart:convert';
|
||
|
import 'dart:developer';
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:data_table_2/data_table_2.dart';
|
||
|
import 'package:intl/intl.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
import 'package:siopas/models/asset_status_model.dart';
|
||
1 year ago
|
import 'package:siopas/models/m_asset_status_model.dart';
|
||
1 year ago
|
import 'package:siopas/pages/pengembalian_barang/show.dart';
|
||
1 year ago
|
import 'package:siopas/pages/transfer_peti/show.dart';
|
||
1 year ago
|
import 'package:siopas/providers/asset_status_provider.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
|
||
|
import '../../connection/connection.dart';
|
||
|
import '../peminjaman_barang/show.dart';
|
||
|
|
||
1 year ago
|
class TransferPetiPage extends StatefulWidget {
|
||
|
const TransferPetiPage({super.key});
|
||
1 year ago
|
|
||
|
@override
|
||
1 year ago
|
State<TransferPetiPage> createState() => TransferPetiPageState();
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
class TransferPetiPageState extends State<TransferPetiPage> {
|
||
1 year ago
|
String? token;
|
||
|
int _currentPage = 1;
|
||
|
int _pageSize = 10;
|
||
1 year ago
|
List<PetiAssetModel> _data = [];
|
||
1 year ago
|
bool _isLoading = false;
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
_getUserToken();
|
||
|
fetchData();
|
||
|
}
|
||
|
|
||
|
void _getUserToken() async {
|
||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
|
if (mounted) {
|
||
|
setState(() {
|
||
|
token = prefs.getString('token');
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Future<void> fetchData() async {
|
||
|
if (mounted) {
|
||
|
setState(() {
|
||
|
_isLoading = true;
|
||
|
});
|
||
|
|
||
|
try {
|
||
1 year ago
|
final response = await http.get(Uri.parse('$baseUrl/peti-asset'));
|
||
1 year ago
|
|
||
|
if (response.statusCode == 200) {
|
||
1 year ago
|
final jsonData = json.decode(response.body)['data']['petis'];
|
||
1 year ago
|
|
||
1 year ago
|
final List<PetiAssetModel> newData = (jsonData as List)
|
||
|
.map((item) => PetiAssetModel.fromJson(item))
|
||
1 year ago
|
.toList();
|
||
|
|
||
|
if (mounted) {
|
||
|
setState(() {
|
||
|
_data.addAll(newData);
|
||
|
_isLoading = false;
|
||
|
});
|
||
|
}
|
||
|
} else {
|
||
|
if (mounted) {
|
||
|
setState(() {
|
||
|
_isLoading = false;
|
||
|
});
|
||
|
}
|
||
|
throw Exception('Failed to fetch data');
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (mounted) {
|
||
|
setState(() {
|
||
|
_isLoading = false;
|
||
|
});
|
||
|
}
|
||
|
print('Error fetching data: $e');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void _loadMoreData() {
|
||
|
if (mounted && !_isLoading) {
|
||
|
setState(() {
|
||
|
_currentPage++;
|
||
|
});
|
||
|
fetchData();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
backgroundColor: Colors.indigo[700],
|
||
|
elevation: 0,
|
||
1 year ago
|
title: Text('Data Peti (Transfer Peti)',
|
||
1 year ago
|
style: TextStyle(
|
||
|
fontSize: 16,
|
||
|
)),
|
||
|
leading: IconButton(
|
||
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
||
|
onPressed: () {
|
||
|
Navigator.pushNamed(context, '/home');
|
||
|
},
|
||
|
),
|
||
|
),
|
||
|
body: _isLoading
|
||
|
? const Center(child: CircularProgressIndicator())
|
||
|
: SingleChildScrollView(
|
||
|
child: SizedBox(
|
||
|
width: double.infinity,
|
||
|
child: PaginatedDataTable(
|
||
1 year ago
|
header: const Text('Menu Peti'),
|
||
1 year ago
|
rowsPerPage: _pageSize,
|
||
|
availableRowsPerPage: const [10, 25, 50],
|
||
|
onRowsPerPageChanged: (value) {
|
||
|
setState(() {
|
||
|
_pageSize = value!;
|
||
|
});
|
||
|
},
|
||
|
columns: const [
|
||
|
DataColumn(label: Text('No')),
|
||
1 year ago
|
DataColumn(label: Text('')),
|
||
1 year ago
|
DataColumn(label: Text('Customer')),
|
||
|
DataColumn(label: Text('Gudang')),
|
||
|
DataColumn(label: Text('Fix Lot')),
|
||
|
DataColumn(label: Text('Tipe Peti')),
|
||
|
DataColumn(label: Text('Ukuran Peti')),
|
||
|
DataColumn(label: Text('Lot No')),
|
||
|
DataColumn(label: Text('Status Peti')),
|
||
|
DataColumn(label: Text('Packing No')),
|
||
1 year ago
|
],
|
||
|
source: _DataSource(data: _data, context: context),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
bottomNavigationBar: BottomAppBar(
|
||
|
color: Color.fromARGB(255, 5, 28, 158), // Warna latar belakang
|
||
|
child: Container(
|
||
|
height: 65.0,
|
||
|
child: Row(
|
||
|
mainAxisSize: MainAxisSize.max,
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: <Widget>[
|
||
|
InkWell(
|
||
|
customBorder: CircleBorder(),
|
||
|
onTap: () {
|
||
|
// Aksi ketika ikon diklik
|
||
1 year ago
|
Navigator.pushNamed(context, '/transfer-peti/edit');
|
||
1 year ago
|
},
|
||
|
child: Container(
|
||
|
width: 45,
|
||
|
height: 45,
|
||
|
decoration: BoxDecoration(
|
||
|
shape: BoxShape.circle,
|
||
1 year ago
|
color: Colors.yellow[800],
|
||
1 year ago
|
),
|
||
|
child: Icon(
|
||
1 year ago
|
Icons.local_shipping,
|
||
1 year ago
|
size: 30,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _DataSource extends DataTableSource {
|
||
1 year ago
|
final List<PetiAssetModel> data;
|
||
1 year ago
|
final BuildContext context;
|
||
|
|
||
|
_DataSource({required this.data, required this.context});
|
||
|
@override
|
||
|
DataRow? getRow(int index) {
|
||
|
if (index >= data.length) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
final item = data[index];
|
||
|
|
||
|
return DataRow(cells: [
|
||
|
DataCell(
|
||
|
Text(
|
||
|
(index + 1).toString(),
|
||
|
),
|
||
|
),
|
||
|
DataCell(
|
||
|
GestureDetector(
|
||
|
onTap: () {
|
||
|
if (item.id != null) {
|
||
|
Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
1 year ago
|
builder: (context) => DetailTransferPetiPage(
|
||
|
petiId: item.id!,
|
||
1 year ago
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
print('asset id: ${item.id}');
|
||
|
}
|
||
|
},
|
||
1 year ago
|
child: Icon(
|
||
|
Icons.article_outlined,
|
||
|
size: 30,
|
||
|
color: Colors.indigo[700],
|
||
1 year ago
|
),
|
||
|
),
|
||
|
),
|
||
1 year ago
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.customer!.name!.toString() != 'null'
|
||
|
? item.customer!.name.toString()
|
||
|
: '-',
|
||
1 year ago
|
),
|
||
|
),
|
||
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.warehouse!.name!.toString() != 'null'
|
||
|
? item.warehouse!.name.toString()
|
||
1 year ago
|
: '-',
|
||
|
),
|
||
|
),
|
||
1 year ago
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.fix_lot.toString() != 'null' ? item.fix_lot.toString() : '-',
|
||
1 year ago
|
),
|
||
|
),
|
||
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.tipe_peti!.type.toString() != 'null'
|
||
|
? item.tipe_peti!.type.toString()
|
||
|
: '-',
|
||
1 year ago
|
),
|
||
|
),
|
||
|
DataCell(
|
||
1 year ago
|
Text(item.tipe_peti!.size_peti.toString() != 'null'
|
||
|
? item.tipe_peti!.size_peti.toString()
|
||
1 year ago
|
: '-'),
|
||
|
),
|
||
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.customer!.lot_no.toString() != 'null'
|
||
|
? item.customer!.lot_no.toString()
|
||
1 year ago
|
: '-',
|
||
|
),
|
||
|
),
|
||
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.status_disposal.toString() != 'null'
|
||
|
? item.status_disposal.toString()
|
||
|
: '-',
|
||
1 year ago
|
),
|
||
|
),
|
||
|
DataCell(
|
||
|
Text(
|
||
1 year ago
|
item.packing_no.toString() != 'null'
|
||
|
? item.packing_no.toString()
|
||
1 year ago
|
: '-',
|
||
|
),
|
||
|
),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
bool get isRowCountApproximate => false;
|
||
|
|
||
|
@override
|
||
|
int get rowCount => data.length;
|
||
|
|
||
|
@override
|
||
|
int get selectedRowCount => 0;
|
||
|
}
|