121 lines
5.0 KiB
Dart
121 lines
5.0 KiB
Dart
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:intl/intl.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
|
||
|
|
import '../../../helpers/theme.dart';
|
||
|
|
import '../../domain/entities/package.dart';
|
||
|
|
import 'model/package_selection_model.dart';
|
||
|
|
|
||
|
|
typedef OnAction = Future<void> Function();
|
||
|
|
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||
|
|
|
||
|
|
class PackageSelectionResult extends StatelessWidget {
|
||
|
|
final bool isLoadingMore;
|
||
|
|
final OnAction onLoadMore;
|
||
|
|
final OnAction onRefresh;
|
||
|
|
final Function(Package)? onTap;
|
||
|
|
final ScrollController controller;
|
||
|
|
|
||
|
|
const PackageSelectionResult(
|
||
|
|
{super.key,
|
||
|
|
required this.isLoadingMore,
|
||
|
|
required this.onLoadMore,
|
||
|
|
required this.onRefresh,
|
||
|
|
this.onTap,
|
||
|
|
required this.controller});
|
||
|
|
|
||
|
|
bool _scrollNotification(ScrollNotification scrollInfo) {
|
||
|
|
if (!isLoadingMore &&
|
||
|
|
scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
|
||
|
|
onLoadMore();
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
var model = context.watch<PackageSelectionModel>();
|
||
|
|
List<Package> searchResults = model.packages;
|
||
|
|
|
||
|
|
return searchResults.isEmpty && !model.isLoading
|
||
|
|
? Center(
|
||
|
|
child: LocalText(context, 'box.no_package',
|
||
|
|
color: Colors.black, fontSize: 15))
|
||
|
|
: Column(children: [
|
||
|
|
Expanded(
|
||
|
|
child: NotificationListener<ScrollNotification>(
|
||
|
|
onNotification: _scrollNotification,
|
||
|
|
child: RefreshIndicator(
|
||
|
|
color: primaryColor,
|
||
|
|
onRefresh: () => onRefresh(),
|
||
|
|
child: ListView.builder(
|
||
|
|
controller: controller,
|
||
|
|
shrinkWrap: true,
|
||
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
||
|
|
itemBuilder: (context, index) {
|
||
|
|
Package package = searchResults[index];
|
||
|
|
|
||
|
|
return Padding(
|
||
|
|
padding: const EdgeInsets.only(top: 5, bottom: 5),
|
||
|
|
child: InkWell(
|
||
|
|
onTap: () {
|
||
|
|
if (onTap != null) {
|
||
|
|
onTap!(package);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
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: new Padding(
|
||
|
|
padding: const EdgeInsets.symmetric(
|
||
|
|
vertical: 8.0),
|
||
|
|
child: new Column(
|
||
|
|
crossAxisAlignment:
|
||
|
|
CrossAxisAlignment.start,
|
||
|
|
children: <Widget>[
|
||
|
|
new Text(package.trackingID ?? "",
|
||
|
|
style: new TextStyle(
|
||
|
|
fontSize: 15.0,
|
||
|
|
color: Colors.black)),
|
||
|
|
new Text(
|
||
|
|
package.cartonIds.isEmpty
|
||
|
|
? "-"
|
||
|
|
: "${numberFormatter.format(package.cartonIds.length)} Boxes",
|
||
|
|
style: new TextStyle(
|
||
|
|
fontSize: 15.0,
|
||
|
|
color: Colors.grey),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
package.isChecked
|
||
|
|
? Icon(Icons.check, color: primaryColor)
|
||
|
|
: const SizedBox()
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
itemCount: searchResults.length)),
|
||
|
|
)),
|
||
|
|
Container(
|
||
|
|
height: isLoadingMore ? 50.0 : 0,
|
||
|
|
color: Colors.transparent,
|
||
|
|
child: const Center(
|
||
|
|
child: CircularProgressIndicator(
|
||
|
|
valueColor: AlwaysStoppedAnimation<Color>(primaryColor)),
|
||
|
|
)),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|