2025-03-12 17:49:27 +06:30
|
|
|
import 'package:fcs/domain/entities/fcs_shipment.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
|
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';
|
|
|
|
|
import '../widgets/continue_button.dart';
|
2025-03-21 18:19:52 +06:30
|
|
|
import '../widgets/local_text.dart';
|
2025-03-12 17:49:27 +06:30
|
|
|
import '../widgets/local_title.dart';
|
|
|
|
|
import '../widgets/previous_button.dart';
|
|
|
|
|
import 'model/package_selection_model.dart';
|
|
|
|
|
import 'package_selection_result.dart';
|
|
|
|
|
|
|
|
|
|
typedef OnPrevious = Function(List<Package> packages);
|
|
|
|
|
typedef OnContinue = Function(List<Package> packages);
|
|
|
|
|
|
|
|
|
|
class PackagesWidget extends StatefulWidget {
|
|
|
|
|
final User sender;
|
|
|
|
|
final User consignee;
|
|
|
|
|
final FcsShipment shipment;
|
|
|
|
|
final OnPrevious? onPrevious;
|
|
|
|
|
final OnContinue? onContinue;
|
|
|
|
|
|
|
|
|
|
const PackagesWidget({
|
|
|
|
|
super.key,
|
|
|
|
|
this.onPrevious,
|
|
|
|
|
this.onContinue,
|
|
|
|
|
required this.shipment,
|
|
|
|
|
required this.sender,
|
|
|
|
|
required this.consignee,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<PackagesWidget> createState() => _PackagesWidgetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PackagesWidgetState extends State<PackagesWidget> {
|
|
|
|
|
final _scrollController = ScrollController();
|
|
|
|
|
bool _down = true;
|
|
|
|
|
List<Package> _packages = [];
|
2025-03-21 18:19:52 +06:30
|
|
|
bool _isLoading = false;
|
2025-03-12 17:49:27 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_init();
|
|
|
|
|
super.initState();
|
|
|
|
|
_scrollController.addListener(() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_down = _scrollController.position.userScrollDirection ==
|
|
|
|
|
ScrollDirection.forward;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_init() async {
|
|
|
|
|
_packages.clear();
|
2025-03-21 18:19:52 +06:30
|
|
|
_isLoading = true;
|
2025-03-12 17:49:27 +06:30
|
|
|
var packageModel = context.read<PackageSelectionModel>();
|
|
|
|
|
var list = await packageModel.getActivePackages(
|
|
|
|
|
shipmentId: widget.shipment.id!,
|
|
|
|
|
senderId: widget.sender.id!,
|
|
|
|
|
consigneeId: widget.consignee.id!);
|
|
|
|
|
_packages = List.from(list);
|
2025-03-21 18:19:52 +06:30
|
|
|
_isLoading = false;
|
2025-03-12 17:49:27 +06:30
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final senderBox = userDisplayBox(context,
|
|
|
|
|
lableKey: "box.sender.title",
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_right,
|
|
|
|
|
showLink: false,
|
|
|
|
|
name: widget.sender.name ?? "",
|
|
|
|
|
fcsID: widget.sender.fcsID ?? "");
|
|
|
|
|
|
|
|
|
|
final consigneeBox = userDisplayBox(context,
|
|
|
|
|
showLink: false,
|
|
|
|
|
lableKey: "box.consignee.title",
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_left,
|
|
|
|
|
name: widget.consignee.name,
|
|
|
|
|
fcsID: widget.consignee.fcsID);
|
|
|
|
|
|
|
|
|
|
final userRow = Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(flex: 2, child: consigneeBox),
|
|
|
|
|
Flexible(child: senderBox)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final continueBtn = ContinueButton(
|
|
|
|
|
onTap: () {
|
2025-03-21 18:19:52 +06:30
|
|
|
if (_packages.isEmpty) {
|
|
|
|
|
showMsgDialog(context, 'Error', "Please add the packages");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-03-12 17:49:27 +06:30
|
|
|
if (widget.onContinue != null) {
|
|
|
|
|
widget.onContinue!(_packages);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final previousBtn = PreviousButton(onTap: () {
|
|
|
|
|
if (widget.onPrevious != null) {
|
|
|
|
|
widget.onPrevious!(_packages);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
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(),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
2025-03-21 18:19:52 +06:30
|
|
|
child: _packages.isEmpty && !_isLoading
|
|
|
|
|
? Center(
|
|
|
|
|
child: LocalText(context, 'box.no_package',
|
|
|
|
|
color: Colors.black, fontSize: 15))
|
|
|
|
|
: RefreshIndicator(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
_init();
|
2025-03-12 17:49:27 +06:30
|
|
|
},
|
2025-03-21 18:19:52 +06:30
|
|
|
child: ListView.builder(
|
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
Package package = _packages[index];
|
|
|
|
|
return packageRow(context, package);
|
|
|
|
|
},
|
|
|
|
|
itemCount: _packages.length)),
|
2025-03-12 17:49:27 +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)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget packageRow(BuildContext context, Package package) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 5, bottom: 5),
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5)),
|
|
|
|
|
border: Border.all(color: Colors.grey.shade300)),
|
|
|
|
|
padding: EdgeInsets.only(left: 10, right: 10),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Text(package.trackingID ?? "",
|
|
|
|
|
style: TextStyle(fontSize: 15.0, color: Colors.black)),
|
|
|
|
|
Text(
|
|
|
|
|
package.cartonIds.isEmpty
|
|
|
|
|
? "-"
|
|
|
|
|
: "${numberFormatter.format(package.cartonIds.length)} Boxes",
|
|
|
|
|
style: TextStyle(fontSize: 15.0, color: Colors.grey),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
package.isChecked
|
|
|
|
|
? Icon(Icons.check, color: primaryColor)
|
|
|
|
|
: const SizedBox()
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|