123 lines
3.5 KiB
Dart
123 lines
3.5 KiB
Dart
|
|
import 'package:fcs/domain/entities/carton.dart';
|
||
|
|
import 'package:fcs/helpers/theme.dart';
|
||
|
|
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
|
||
|
|
import 'carton_list_row.dart';
|
||
|
|
|
||
|
|
typedef CallbackCartonSelect(Carton carton);
|
||
|
|
|
||
|
|
Future<Carton> searchCarton(BuildContext context,
|
||
|
|
{CallbackCartonSelect callbackCartonSelect}) async =>
|
||
|
|
await showSearch<Carton>(
|
||
|
|
context: context,
|
||
|
|
delegate: PartSearchDelegate(callbackCartonSelect: callbackCartonSelect),
|
||
|
|
);
|
||
|
|
|
||
|
|
class PartSearchDelegate extends SearchDelegate<Carton> {
|
||
|
|
final CallbackCartonSelect callbackCartonSelect;
|
||
|
|
PartSearchDelegate({this.callbackCartonSelect});
|
||
|
|
|
||
|
|
@override
|
||
|
|
String get searchFieldLabel => 'Search by Carton Number/Customer Name';
|
||
|
|
|
||
|
|
@override
|
||
|
|
ThemeData appBarTheme(BuildContext context) {
|
||
|
|
final ThemeData theme = Theme.of(context);
|
||
|
|
return theme.copyWith(
|
||
|
|
inputDecorationTheme: InputDecorationTheme(
|
||
|
|
hintStyle: TextStyle(
|
||
|
|
color: theme.primaryTextTheme.caption.color, fontSize: 14)),
|
||
|
|
textTheme: theme.textTheme.copyWith(
|
||
|
|
title: theme.textTheme.title.copyWith(
|
||
|
|
color: theme.primaryTextTheme.title.color, fontSize: 16)),
|
||
|
|
primaryColor: primaryColor,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
List<Widget> buildActions(BuildContext context) {
|
||
|
|
return [
|
||
|
|
IconButton(
|
||
|
|
icon: Icon(Icons.clear),
|
||
|
|
onPressed: () => query = '',
|
||
|
|
),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget buildLeading(BuildContext context) {
|
||
|
|
return IconButton(
|
||
|
|
icon: Icon(Icons.arrow_back),
|
||
|
|
onPressed: () => close(context, null),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget buildResults(BuildContext context) {
|
||
|
|
final cartonModel = Provider.of<CartonModel>(context);
|
||
|
|
return FutureBuilder(
|
||
|
|
future: cartonModel.searchCarton(query),
|
||
|
|
builder: (context, AsyncSnapshot<List<Carton>> snapshot) {
|
||
|
|
if (snapshot.hasData) {
|
||
|
|
if (snapshot.data.length == 0) {
|
||
|
|
return Container(
|
||
|
|
child: Center(
|
||
|
|
child: Text(
|
||
|
|
"No result found",
|
||
|
|
textAlign: TextAlign.center,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
return Container(
|
||
|
|
padding: EdgeInsets.only(top: 15),
|
||
|
|
child: ListView(
|
||
|
|
children: snapshot.data
|
||
|
|
.map((u) => CartonListRow(
|
||
|
|
carton: u,
|
||
|
|
callbackCartonSelect: callbackCartonSelect,
|
||
|
|
))
|
||
|
|
.toList(),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
} else if (snapshot.hasError) {
|
||
|
|
return Container(
|
||
|
|
child: Center(
|
||
|
|
child: Text(
|
||
|
|
'${snapshot.error}',
|
||
|
|
textAlign: TextAlign.center,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
return Container(
|
||
|
|
child: Center(
|
||
|
|
child: CircularProgressIndicator(
|
||
|
|
valueColor:
|
||
|
|
new AlwaysStoppedAnimation<Color>(primaryColor)),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget buildSuggestions(BuildContext context) {
|
||
|
|
return Container(
|
||
|
|
child: Center(
|
||
|
|
child: Opacity(
|
||
|
|
opacity: 0.2,
|
||
|
|
child: Icon(
|
||
|
|
MaterialCommunityIcons.package,
|
||
|
|
color: primaryColor,
|
||
|
|
size: 200,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|