117 lines
4.7 KiB
Dart
117 lines
4.7 KiB
Dart
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../domain/entities/carton.dart';
|
|
import '../../../helpers/theme.dart';
|
|
import '../model/carton_selection_model.dart';
|
|
|
|
typedef OnAction = Future<void> Function();
|
|
|
|
class CartonSelectionResult extends StatelessWidget {
|
|
final bool isLoadingMore;
|
|
final OnAction onLoadMore;
|
|
final OnAction onRefresh;
|
|
final Function(Carton)? onTap;
|
|
final ScrollController controller;
|
|
|
|
const CartonSelectionResult(
|
|
{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<CartonSelectionModel>();
|
|
List<Carton> searchResults = model.cartons;
|
|
|
|
return searchResults.isEmpty && !model.isLoading
|
|
? Center(
|
|
child: LocalText(context, 'box.no_carton',
|
|
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) {
|
|
Carton carton = searchResults[index];
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 5, bottom: 5),
|
|
child: InkWell(
|
|
onTap: () {
|
|
if (onTap != null) {
|
|
onTap!(carton);
|
|
}
|
|
},
|
|
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(carton.cartonNumber ?? "",
|
|
style: new TextStyle(
|
|
fontSize: 15.0,
|
|
color: Colors.black)),
|
|
new Text(
|
|
"${carton.cartonWeight.toStringAsFixed(2)} lb",
|
|
style: new TextStyle(
|
|
fontSize: 15.0,
|
|
color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
carton.isSelected
|
|
? 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)),
|
|
)),
|
|
]);
|
|
}
|
|
}
|