Skip to content

Instantly share code, notes, and snippets.

@jafar260698
Created February 12, 2024 04:22
Show Gist options
  • Save jafar260698/045395dd96b3f3246406a373b9218c91 to your computer and use it in GitHub Desktop.
Save jafar260698/045395dd96b3f3246406a373b9218c91 to your computer and use it in GitHub Desktop.
TypeAheadField<Patient>(
suggestionsCallback: (search) {
return model.searchPatient;
},
builder: (context, controller, focusNode) {
return SearchUI(
controller: controller,
focusNode: focusNode,
hintText: getTranslated(context, 'search'),
keyboardType: TextInputType.text,
style: AppStyles.title16,
prefixIcon: model.isSearchLoading ? const CupertinoActivityIndicator() : const Icon(CupertinoIcons.search, size: 22),
suffixIcon: InkWell(
onTap: () => model.clearSearch(),
child: Ink(child: const Icon(Icons.close)),
),
onChanged: (value) => model.searchData(controller.text),
);
},
itemBuilder: (context, patient) {
return Padding(
padding: const EdgeInsets.all(defaultPadding / 2),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("${patient.username}", style: AppStyles.title15BgColor),
Text("${patient.phone}", style: AppStyles.title15BgColor),
ContainerUISmall(
labelText: getTranslated(context, 'apply_treatment'),
fontSize: 13,
color: Colors.green,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
onPressed: () async {}
),
ContainerUISmall(
labelText: getTranslated(context, 'detail'),
fontSize: 13,
color: Colors.blue.shade50,
txtColor: AppColors.primaryColorCongress,
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 4),
onPressed: () {
AutoRouterX(context).router.push(PatientReviewRoute(patientsInfoBase: patient));
}
),
],
),
),
);
},
animationDuration: const Duration(milliseconds: 300),
itemSeparatorBuilder: (context, index) {
return const Divider();
},
decorationBuilder: (context, child) {
return CardShadow(
child: child,
);
},
hideOnEmpty: model.isHideOnly,
emptyBuilder: (context) {
return Padding(
padding: const EdgeInsets.all(defaultPadding),
child: Text("Ma'lumot topilmadi", style: AppStyles.title14BgColor, textAlign: TextAlign.center),
);
},
onSelected: (city) {
},
),
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:theme_provider/theme_provider.dart';
import '../../utils/app_responsive/device_size_config.dart';
import '../theme/app_color.dart';
import '../theme/app_style.dart';
class SearchUI extends StatefulWidget {
const SearchUI(
{super.key, this.hintText,
this.errorText,
this.errorValidate = false,
this.enabled = true,
this.helperText,
this.onSaved,
this.style,
this.focusNode,
this.validator,
this.onFieldSubmitted,
this.suffixIcon,
this.suffixIconConstraints,
this.keyboardType = TextInputType.multiline,
this.text = '',
this.isTextHas = false,
this.controller,
this.inputFormatters,
this.minLine = 1,
this.maxLine = 1,
this.inputAction = TextInputAction.next,
this.textCapitalization = TextCapitalization.sentences,
this.textMaxLength,
this.counterText,
this.onChanged,
this.hasIcon = false,
this.isPhoneNumber = false,
this.isReadOnly = false,
this.prefixText,
this.showCursor = true,
this.color,
this.initialValue,
this.prefixIcon,
this.autoFocus = false,
this.onPressedSuffix,
this.obscureText = false
});
final String text;
final bool isTextHas;
final String? hintText;
final String? errorText;
final String? prefixText;
final String? initialValue;
final bool errorValidate;
final bool? enabled;
final String? helperText;
final Widget? prefixIcon;
final TextStyle? style;
final FocusNode? focusNode;
final bool showCursor;
final Color? color;
final TextEditingController? controller;
final suffixIcon;
final suffixIconConstraints;
final keyboardType;
final FormFieldSetter<String>? onSaved;
final FormFieldValidator<String>? validator;
final ValueChanged<String>? onFieldSubmitted;
final List<TextInputFormatter>? inputFormatters;
final TextCapitalization textCapitalization;
final minLine;
final maxLine;
final TextInputAction inputAction;
final textMaxLength;
final counterText;
final onChanged;
final bool hasIcon;
final bool isPhoneNumber;
final bool isReadOnly;
final bool autoFocus;
final bool obscureText;
final GestureTapCallback? onPressedSuffix;
@override
_SearchUI createState() => _SearchUI();
}
class _SearchUI extends State<SearchUI> {
@override
Widget build(BuildContext context) {
var theme = ThemeProvider.controllerOf(context).theme.data;
return TextFormField(
obscureText: widget.obscureText,
initialValue: widget.initialValue,
showCursor: widget.showCursor,
maxLength: widget.textMaxLength,
readOnly: widget.isReadOnly,
autofocus: widget.autoFocus,
focusNode: widget.focusNode,
style: widget.isPhoneNumber
? AppStyles.title15
: (widget.style ?? AppStyles.title15),
textInputAction: widget.inputAction,
controller: widget.controller,
enabled: widget.enabled,
inputFormatters: widget.inputFormatters,
textCapitalization: widget.textCapitalization,
onSaved: widget.onSaved,
minLines: widget.minLine,
maxLines: widget.maxLine,
validator: widget.validator,
onFieldSubmitted: widget.onFieldSubmitted,
keyboardType: widget.keyboardType,
onChanged: widget.onChanged,
decoration: InputDecoration(
contentPadding: const EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 10.0),
suffixIconConstraints: widget.suffixIconConstraints != null
? const BoxConstraints(minHeight: 24, minWidth: 38)
: widget.suffixIconConstraints,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
hintStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
letterSpacing: 0.2,
color: AppColors.greyColor),
hintText: widget.hintText,
labelStyle: AppStyles.title16,
helperText: widget.helperText,
prefixIcon: widget.prefixIcon,
suffixIcon: widget.suffixIcon != null ? IconButton(
icon: widget.suffixIcon,
onPressed: widget.onPressedSuffix,
) : null
),
);
}
}
final List<Patient> _searchPatient = [];
List<Patient>? get searchPatient => _searchPatient;
Patient? _selectedPatient;
Patient? get selectedPatient => _selectedPatient;
bool _isSearchLoading = false;
bool get isSearchLoading => _isSearchLoading;
bool _isHideOnly = true;
bool get isHideOnly => _isHideOnly;
Future<void> searchData(String search) async {
try {
if(search.length >= 3) {
_isSearchLoading = true;
notifyListeners();
var response = await _apiProvider.searchPatient(search);
if(response.success! && response.data != null) {
_searchPatient.clear();
_searchPatient.addAll(response.data!);
if(_searchPatient.isEmpty) {
_isHideOnly = false;
notifyListeners();
}
}
} else {
_isHideOnly = true;
_searchPatient.clear();
_isSearchLoading = false;
notifyListeners();
}
} catch(e) {
print("Exeption $e");
} finally {
_isSearchLoading = false;
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment