|
|
|
|
@ -11,12 +11,16 @@ import 'package:diplomaticquarterapp/widgets/input/text_field.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'base/base_view.dart';
|
|
|
|
|
import 'package:intl/intl.dart' as international;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchProductsPage extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
@ -27,6 +31,8 @@ class _SearchProductsPageState extends State<SearchProductsPage> {
|
|
|
|
|
final textController = TextEditingController();
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
String msg = '';
|
|
|
|
|
String validText="";
|
|
|
|
|
bool isTextValid = true;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
@ -55,47 +61,90 @@ class _SearchProductsPageState extends State<SearchProductsPage> {
|
|
|
|
|
width: MediaQuery.of(context).size.width * 0.70,
|
|
|
|
|
child: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: TextFields(
|
|
|
|
|
autoFocus: true,
|
|
|
|
|
hintText: TranslationBase.of(context).search,
|
|
|
|
|
fontSize: 14.5,
|
|
|
|
|
prefixIcon: Icon(Icons.search),
|
|
|
|
|
inputAction: TextInputAction.search,
|
|
|
|
|
inputFormatters: <TextInputFormatter>[
|
|
|
|
|
FilteringTextInputFormatter.allow(
|
|
|
|
|
RegExp(r'([A-Za-z0-9 a space])'))
|
|
|
|
|
],
|
|
|
|
|
validator: (value) {
|
|
|
|
|
RegExp regExp = RegExp(r'([A-Za-z0-9 a space])');
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.pleaseEnterProductName;
|
|
|
|
|
} else if (!regExp.hasMatch(value)) {
|
|
|
|
|
AppToast.showErrorToast(
|
|
|
|
|
message: TranslationBase.of(context)
|
|
|
|
|
.noArabicLetters);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
//searchMedicine(model, context);
|
|
|
|
|
},
|
|
|
|
|
onSubmit: (value) {
|
|
|
|
|
searchMedicine(model, context);
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
TextFields(
|
|
|
|
|
autoFocus: true,
|
|
|
|
|
hintText: TranslationBase.of(context).search,
|
|
|
|
|
fontSize: 14.5,
|
|
|
|
|
prefixIcon: Icon(Icons.search),
|
|
|
|
|
inputAction: TextInputAction.search,
|
|
|
|
|
|
|
|
|
|
validator: (value) {
|
|
|
|
|
RegExp regExp = RegExp(r'([A-Za-z0-9 a space])');
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.pleaseEnterProductName;
|
|
|
|
|
} else if (isRTL(value)) {
|
|
|
|
|
AppToast.showErrorToast(
|
|
|
|
|
message: TranslationBase.of(context)
|
|
|
|
|
.noArabicLetters);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
onChanged: (value){
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
TranslationBase.of(context)
|
|
|
|
|
.pleaseEnterProductName;
|
|
|
|
|
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 10), (){
|
|
|
|
|
setState(() {
|
|
|
|
|
textController.text = "";
|
|
|
|
|
isTextValid = true;
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (isRTL(value)) {
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 10), (){
|
|
|
|
|
setState(() {
|
|
|
|
|
textController.text = validText;
|
|
|
|
|
isTextValid = false;
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 10), (){
|
|
|
|
|
setState(() {
|
|
|
|
|
textController.text = value;
|
|
|
|
|
validText = value;
|
|
|
|
|
isTextValid = true;
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
textController.text = validText;
|
|
|
|
|
isTextValid = false;
|
|
|
|
|
});
|
|
|
|
|
//searchMedicine(model, context);
|
|
|
|
|
},
|
|
|
|
|
onSubmit: (value) {
|
|
|
|
|
searchMedicine(model, context);
|
|
|
|
|
// msg = 'No Result Found';
|
|
|
|
|
msg = TranslationBase.of(context).noResultFound;
|
|
|
|
|
},
|
|
|
|
|
controller: textController,
|
|
|
|
|
// validator: (value) {
|
|
|
|
|
// if (value.isEmpty) {
|
|
|
|
|
//// return 'please Enter Product Name';
|
|
|
|
|
// return TranslationBase.of(context).pleaseEnterProductName;
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// },
|
|
|
|
|
msg = TranslationBase.of(context).noResultFound;
|
|
|
|
|
},
|
|
|
|
|
controller: textController,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 10.0,
|
|
|
|
|
),
|
|
|
|
|
if(!isTextValid)
|
|
|
|
|
AppText( TranslationBase.of(context)
|
|
|
|
|
.noArabicLetters, color: Colors.red,),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 10.0,
|
|
|
|
|
),
|
|
|
|
|
@ -337,7 +386,9 @@ class _SearchProductsPageState extends State<SearchProductsPage> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isRTL(String text) {
|
|
|
|
|
return international.Bidi.detectRtlDirectionality(text);
|
|
|
|
|
}
|
|
|
|
|
searchMedicine(PharmacyCategoriseViewModel model, BuildContext context) {
|
|
|
|
|
Utils.hideKeyboard(context);
|
|
|
|
|
if (_formKey.currentState.validate())
|
|
|
|
|
|