You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
5.3 KiB
Dart
150 lines
5.3 KiB
Dart
|
2 years ago
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
||
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
||
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
||
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||
|
|
|
||
|
|
import '../../../models/device/asset_search.dart';
|
||
|
|
import '../../../new_views/common_widgets/app_lazy_loading.dart';
|
||
|
|
import '../../../new_views/common_widgets/default_app_bar.dart';
|
||
|
|
|
||
|
|
class AssetSearchScreen extends StatefulWidget {
|
||
|
|
static const String id = "asset_search_screen";
|
||
|
|
final AssetSearch data;
|
||
|
|
const AssetSearchScreen({Key key, this.data}) : super(key: key);
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<AssetSearchScreen> createState() => _AssetSearchScreenState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _AssetSearchScreenState extends State<AssetSearchScreen> {
|
||
|
|
AssetSearch search;
|
||
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
search = widget.data ?? AssetSearch();
|
||
|
|
super.initState();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return Scaffold(
|
||
|
|
appBar: DefaultAppBar(title: context.translation.search),
|
||
|
|
body: Form(
|
||
|
|
key: _formKey,
|
||
|
|
child: Column(
|
||
|
|
children: [
|
||
|
|
SingleChildScrollView(
|
||
|
|
child: Column(
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
|
|
children: [
|
||
|
|
context.translation.searchBy.heading5(context),
|
||
|
|
8.height,
|
||
|
|
context.translation.searchByDesc.bodyText(context),
|
||
|
|
16.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.assetName,
|
||
|
|
initialValue: search.assetName,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.assetName = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.assetNumber,
|
||
|
|
initialValue: search.assetNo,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.assetNo = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
|
||
|
|
/// todo : TBD (no matched parameter)
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.oracleCode,
|
||
|
|
onSaved: (value) {},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.snNumber,
|
||
|
|
initialValue: search.assetSerialNumber,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.assetSerialNumber = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.model,
|
||
|
|
initialValue: search.model,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.model = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.supplier,
|
||
|
|
initialValue: search.supplier,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.supplier = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.site,
|
||
|
|
initialValue: search.site,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.site = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.manufacture,
|
||
|
|
initialValue: search.manufacturer,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.manufacturer = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.md,
|
||
|
|
initialValue: search.modelDefinition,
|
||
|
|
onSaved: (value) {
|
||
|
|
search.modelDefinition = value;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
|
||
|
|
/// todo : TBD (no matched parameter)
|
||
|
|
AppTextFormField(
|
||
|
|
labelText: context.translation.location,
|
||
|
|
onSaved: (value) {},
|
||
|
|
),
|
||
|
|
8.height,
|
||
|
|
],
|
||
|
|
),
|
||
|
|
).expanded,
|
||
|
|
AppFilledButton(onPressed: _search, label: context.translation.search),
|
||
|
|
],
|
||
|
|
).paddingAll(16),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
void _search() async {
|
||
|
|
if (_formKey.currentState.validate()) {
|
||
|
|
_formKey.currentState.save();
|
||
|
|
final deviceProvider = Provider.of<AssetProvider>(context, listen: false);
|
||
|
|
deviceProvider.reset();
|
||
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||
|
|
await deviceProvider.getAssets(search: search);
|
||
|
|
Navigator.pop(context);
|
||
|
|
Navigator.of(context).pop(search);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|