From d22608ac0101c9f21f72f84cdf1e5b39f4d89030 Mon Sep 17 00:00:00 2001 From: Tanish2002 Date: Mon, 26 Feb 2024 01:36:19 +0530 Subject: [PATCH] feat: update flutter_typeahead --- lib/widgets/headerfield.dart | 40 +++++++++---------- pubspec.lock | 76 +++++++++++++++++++++++++++++------- pubspec.yaml | 2 +- 3 files changed, 82 insertions(+), 36 deletions(-) diff --git a/lib/widgets/headerfield.dart b/lib/widgets/headerfield.dart index 9c678ee3..52dd8ec5 100644 --- a/lib/widgets/headerfield.dart +++ b/lib/widgets/headerfield.dart @@ -1,6 +1,6 @@ +import 'package:apidash/consts.dart'; import 'package:apidash/utils/header_utils.dart'; import 'package:flutter/material.dart'; -import 'package:apidash/consts.dart'; import 'package:flutter_typeahead/flutter_typeahead.dart'; class HeaderField extends StatefulWidget { @@ -41,6 +41,7 @@ class _HeaderFieldState extends State { @override void didUpdateWidget(HeaderField oldWidget) { + super.didUpdateWidget(oldWidget); if (oldWidget.initialValue != widget.initialValue) { controller.text = widget.initialValue ?? ""; controller.selection = @@ -53,9 +54,9 @@ class _HeaderFieldState extends State { var colorScheme = widget.colorScheme ?? Theme.of(context).colorScheme; return TypeAheadField( key: Key(widget.keyId), - hideOnEmpty: true, - minCharsForSuggestions: 1, - onSuggestionSelected: (value) { + hideOnEmpty: false, + controller: controller, + onSelected: (value) { setState(() { controller.text = value; }); @@ -68,19 +69,16 @@ class _HeaderFieldState extends State { ); }, suggestionsCallback: headerSuggestionCallback, - suggestionsBoxDecoration: suggestionBoxDecorations(context), - textFieldConfiguration: TextFieldConfiguration( + decorationBuilder: suggestionBoxDecorations, + constraints: const BoxConstraints(maxHeight: 400), + builder: (context, controller, focusNode) => TextField( onChanged: widget.onChanged, controller: controller, - style: kCodeStyle.copyWith( - color: colorScheme.onSurface, - ), + focusNode: focusNode, + style: kCodeStyle.copyWith(color: colorScheme.onSurface), decoration: InputDecoration( hintStyle: kCodeStyle.copyWith( - color: colorScheme.outline.withOpacity( - kHintOpacity, - ), - ), + color: colorScheme.outline.withOpacity(kHintOpacity)), hintText: widget.hintText, focusedBorder: UnderlineInputBorder( borderSide: BorderSide( @@ -99,22 +97,22 @@ class _HeaderFieldState extends State { ); } - SuggestionsBoxDecoration suggestionBoxDecorations(BuildContext context) { - return SuggestionsBoxDecoration( + Material suggestionBoxDecorations(BuildContext context, Widget child) { + return Material( elevation: 4, - constraints: const BoxConstraints(maxHeight: 400), shape: RoundedRectangleBorder( - side: BorderSide( - color: Theme.of(context).dividerColor, - width: 1.2, - ), + side: BorderSide(color: Theme.of(context).dividerColor, width: 1.2), borderRadius: const BorderRadius.vertical(bottom: Radius.circular(8)), ), clipBehavior: Clip.hardEdge, + child: child, ); } - Future> headerSuggestionCallback(String pattern) async { + Future?> headerSuggestionCallback(String pattern) async { + if (pattern.isEmpty) { + return null; + } return getHeaderSuggestions(pattern); } } diff --git a/pubspec.lock b/pubspec.lock index 2f3f7f55..70dda7d5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -306,10 +306,10 @@ packages: dependency: transitive description: name: flutter_keyboard_visibility - sha256: "4983655c26ab5b959252ee204c2fffa4afeb4413cd030455194ec0caa3b8e7cb" + sha256: "98664be7be0e3ffca00de50f7f6a287ab62c763fc8c762e0a21584584a3ff4f8" url: "https://pub.dev" source: hosted - version: "5.4.1" + version: "6.0.0" flutter_keyboard_visibility_linux: dependency: transitive description: @@ -407,10 +407,10 @@ packages: dependency: "direct main" description: name: flutter_typeahead - sha256: b9942bd5b7611a6ec3f0730c477146cffa4cd4b051077983ba67ddfc9e7ee818 + sha256: d64712c65db240b1057559b952398ebb6e498077baeebf9b0731dade62438a6d url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "5.2.0" flutter_web_plugins: dependency: transitive description: flutter @@ -625,6 +625,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -661,26 +685,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" mime: dependency: transitive description: @@ -757,10 +781,10 @@ packages: dependency: "direct main" description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" path_parsing: dependency: transitive description: @@ -853,10 +877,34 @@ packages: dependency: transitive description: name: pointer_interceptor - sha256: adf7a637f97c077041d36801b43be08559fd4322d2127b3f20bb7be1b9eebc22 + sha256: bd18321519718678d5fa98ad3a3359cbc7a31f018554eab80b73d08a7f0c165a url: "https://pub.dev" source: hosted - version: "0.9.3+7" + version: "0.10.1" + pointer_interceptor_ios: + dependency: transitive + description: + name: pointer_interceptor_ios + sha256: "2e73c39452830adc4695757130676a39412a3b7f3c34e3f752791b5384770877" + url: "https://pub.dev" + source: hosted + version: "0.10.0+2" + pointer_interceptor_platform_interface: + dependency: transitive + description: + name: pointer_interceptor_platform_interface + sha256: "0597b0560e14354baeb23f8375cd612e8bd4841bf8306ecb71fcd0bb78552506" + url: "https://pub.dev" + source: hosted + version: "0.10.0+1" + pointer_interceptor_web: + dependency: transitive + description: + name: pointer_interceptor_web + sha256: "9386e064097fd16419e935c23f08f35b58e6aaec155dd39bd6a003b88f9c14b4" + url: "https://pub.dev" + source: hosted + version: "0.10.1+2" pointycastle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4196d007..075d9695 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,7 +41,7 @@ dependencies: json_annotation: ^4.8.1 printing: ^5.11.1 package_info_plus: ^4.1.0 - flutter_typeahead: ^4.8.0 + flutter_typeahead: ^5.2.0 provider: ^6.0.5 json_data_explorer: git: