2024-02-05 17:49:12 +06:30
|
|
|
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
2025-03-25 17:38:51 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2024-02-05 17:49:12 +06:30
|
|
|
import 'package:flutter/material.dart';
|
2024-02-13 17:48:06 +06:30
|
|
|
import 'package:flutter/rendering.dart';
|
2024-02-05 17:49:12 +06:30
|
|
|
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import '../../domain/entities/package.dart';
|
|
|
|
|
import '../../domain/entities/user.dart';
|
|
|
|
|
import '../main/util.dart';
|
2025-03-25 17:38:51 +06:30
|
|
|
import '../package/package_info.dart';
|
2024-02-05 17:49:12 +06:30
|
|
|
import '../widgets/continue_button.dart';
|
|
|
|
|
import '../widgets/local_title.dart';
|
|
|
|
|
import '../widgets/previous_button.dart';
|
|
|
|
|
import 'model/package_selection_model.dart';
|
|
|
|
|
import 'package_selection_result.dart';
|
|
|
|
|
|
2025-03-25 17:38:51 +06:30
|
|
|
typedef OnPrevious = Function();
|
|
|
|
|
typedef OnContinue = Function();
|
2024-02-05 17:49:12 +06:30
|
|
|
|
|
|
|
|
class PackageSelectionWidget extends StatefulWidget {
|
|
|
|
|
final User sender;
|
|
|
|
|
final User consignee;
|
|
|
|
|
final FcsShipment shipment;
|
|
|
|
|
final OnPrevious? onPrevious;
|
|
|
|
|
final OnContinue? onContinue;
|
|
|
|
|
|
|
|
|
|
const PackageSelectionWidget({
|
2025-03-07 17:41:09 +06:30
|
|
|
super.key,
|
2024-02-05 17:49:12 +06:30
|
|
|
this.onPrevious,
|
|
|
|
|
this.onContinue,
|
|
|
|
|
required this.shipment,
|
|
|
|
|
required this.sender,
|
|
|
|
|
required this.consignee,
|
2025-03-07 17:41:09 +06:30
|
|
|
});
|
2024-02-05 17:49:12 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<PackageSelectionWidget> createState() => _PackageSelectionWidgetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PackageSelectionWidgetState extends State<PackageSelectionWidget> {
|
|
|
|
|
bool _isLoadMore = false;
|
|
|
|
|
final _scrollController = ScrollController();
|
2024-02-13 17:48:06 +06:30
|
|
|
bool _down = true;
|
2024-02-05 17:49:12 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_init();
|
|
|
|
|
super.initState();
|
2024-02-13 17:48:06 +06:30
|
|
|
_scrollController.addListener(() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_down = _scrollController.position.userScrollDirection ==
|
|
|
|
|
ScrollDirection.forward;
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-02-05 17:49:12 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_init() {
|
2025-03-25 17:38:51 +06:30
|
|
|
var packageModel = context.read<PackageSelectionModel>();
|
|
|
|
|
packageModel.refresh(
|
|
|
|
|
shipmentId: widget.shipment.id!,
|
|
|
|
|
consigneeId: widget.consignee.id!,
|
|
|
|
|
senderId: widget.sender.id!,
|
|
|
|
|
);
|
2024-03-02 18:15:05 +06:30
|
|
|
|
2024-02-05 17:49:12 +06:30
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _loadMoreData() async {
|
|
|
|
|
if (_isLoadMore) return;
|
|
|
|
|
var model = context.read<PackageSelectionModel>();
|
2024-03-04 17:09:47 +06:30
|
|
|
if (model.ended) return;
|
2024-02-05 17:49:12 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoadMore = true;
|
|
|
|
|
});
|
2024-03-04 17:09:47 +06:30
|
|
|
|
|
|
|
|
await model.loadMoreData(
|
2025-03-25 17:38:51 +06:30
|
|
|
shipmentId: widget.shipment.id!,
|
|
|
|
|
consigneeId: widget.consignee.id!,
|
|
|
|
|
senderId: widget.sender.id!,
|
|
|
|
|
);
|
2024-02-05 17:49:12 +06:30
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoadMore = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
var model = context.watch<PackageSelectionModel>();
|
2025-03-25 17:38:51 +06:30
|
|
|
List<Package> packages = model.packages;
|
2024-02-05 17:49:12 +06:30
|
|
|
|
2025-03-07 17:41:09 +06:30
|
|
|
final senderBox = userDisplayBox(context,
|
|
|
|
|
lableKey: "box.sender.title",
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_right,
|
|
|
|
|
showLink: false,
|
|
|
|
|
name: widget.sender.name ?? "",
|
|
|
|
|
fcsID: widget.sender.fcsID ?? "");
|
2024-02-05 17:49:12 +06:30
|
|
|
|
2025-03-07 17:41:09 +06:30
|
|
|
final consigneeBox = userDisplayBox(context,
|
|
|
|
|
showLink: false,
|
|
|
|
|
lableKey: "box.consignee.title",
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_left,
|
|
|
|
|
name: widget.consignee.name,
|
|
|
|
|
fcsID: widget.consignee.fcsID);
|
2024-02-05 17:49:12 +06:30
|
|
|
|
|
|
|
|
final userRow = Row(
|
2024-09-23 18:36:23 +06:30
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-02-05 17:49:12 +06:30
|
|
|
children: [
|
2025-03-07 17:41:09 +06:30
|
|
|
Expanded(flex: 2, child: consigneeBox),
|
|
|
|
|
Flexible(child: senderBox)
|
2024-02-05 17:49:12 +06:30
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final continueBtn = ContinueButton(
|
|
|
|
|
onTap: () {
|
2025-03-25 17:38:51 +06:30
|
|
|
if (packages.isEmpty) {
|
|
|
|
|
showMsgDialog(context, 'Error', "Please add the packages");
|
2024-02-05 17:49:12 +06:30
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (widget.onContinue != null) {
|
2025-03-25 17:38:51 +06:30
|
|
|
widget.onContinue!();
|
2024-02-05 17:49:12 +06:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final previousBtn = PreviousButton(onTap: () {
|
|
|
|
|
if (widget.onPrevious != null) {
|
2025-03-25 17:38:51 +06:30
|
|
|
widget.onPrevious!();
|
2024-02-05 17:49:12 +06:30
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
2024-02-13 17:48:06 +06:30
|
|
|
AnimatedSwitcher(
|
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
|
transitionBuilder:
|
|
|
|
|
(Widget child, Animation<double> animation) =>
|
|
|
|
|
FadeTransition(
|
|
|
|
|
opacity: animation,
|
|
|
|
|
child: SizeTransition(
|
|
|
|
|
sizeFactor: animation,
|
|
|
|
|
axis: Axis.vertical,
|
|
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: _down
|
|
|
|
|
? Column(children: [
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
userRow,
|
|
|
|
|
LocalTitle(
|
|
|
|
|
textKey: "box.select.package", topPadding: 5),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
])
|
|
|
|
|
: const SizedBox(),
|
|
|
|
|
),
|
2024-02-05 17:49:12 +06:30
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
child: PackageSelectionResult(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
isLoadingMore: _isLoadMore,
|
|
|
|
|
onLoadMore: _loadMoreData,
|
|
|
|
|
onRefresh: () async {
|
2024-03-04 17:09:47 +06:30
|
|
|
_init();
|
2024-02-13 17:48:06 +06:30
|
|
|
setState(() {
|
|
|
|
|
_down = true;
|
|
|
|
|
});
|
2024-02-05 17:49:12 +06:30
|
|
|
},
|
2025-03-25 17:38:51 +06:30
|
|
|
onTap: (a) {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => PackageInfo(package: a)),
|
|
|
|
|
);
|
2024-02-05 17:49:12 +06:30
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
widget.onContinue != null
|
|
|
|
|
? Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 15, right: 15, top: 10),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
previousBtn,
|
|
|
|
|
continueBtn,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: const SizedBox(),
|
|
|
|
|
const SizedBox(height: 20)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|