make styles consistent and ignore case when matching suggestions
This commit is contained in:
@@ -20,4 +20,7 @@
|
|||||||
extension StringExtension on String {
|
extension StringExtension on String {
|
||||||
String toCapitalized() =>
|
String toCapitalized() =>
|
||||||
isEmpty ? this : '${this[0].toUpperCase()}${substring(1)}';
|
isEmpty ? this : '${this[0].toUpperCase()}${substring(1)}';
|
||||||
|
|
||||||
|
bool startsWithIgnoreCase(String prefix) =>
|
||||||
|
toLowerCase().startsWith(prefix.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:nullability/nullability.dart';
|
import 'package:nullability/nullability.dart';
|
||||||
|
import 'package:weblibre/extensions/string.dart';
|
||||||
import 'package:weblibre/utils/text_field_line_count.dart';
|
import 'package:weblibre/utils/text_field_line_count.dart';
|
||||||
|
|
||||||
class AutoSuggestTextField extends HookWidget {
|
class AutoSuggestTextField extends HookWidget {
|
||||||
@@ -86,26 +87,25 @@ class AutoSuggestTextField extends HookWidget {
|
|||||||
bool _suggestionHasMatch() =>
|
bool _suggestionHasMatch() =>
|
||||||
suggestion != null &&
|
suggestion != null &&
|
||||||
controller.text.isNotEmpty &&
|
controller.text.isNotEmpty &&
|
||||||
suggestion!.startsWith(controller.text);
|
suggestion!.startsWithIgnoreCase(controller.text);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textFieldKey =
|
final textFieldKey =
|
||||||
this.textFieldKey ?? useMemoized<GlobalKey>(() => GlobalKey());
|
this.textFieldKey ?? useMemoized<GlobalKey>(() => GlobalKey());
|
||||||
|
|
||||||
|
final effectiveStyle = style ?? Theme.of(context).textTheme.bodyLarge!;
|
||||||
|
|
||||||
final showSuggestion = useListenableSelector(controller, () {
|
final showSuggestion = useListenableSelector(controller, () {
|
||||||
if (maxLines != 1) {
|
if (maxLines != 1) {
|
||||||
final lines = getTextFieldLineCount(
|
final lines = getTextFieldLineCount(
|
||||||
textFieldKey,
|
textFieldKey,
|
||||||
controller.text,
|
controller.text,
|
||||||
style ?? Theme.of(context).textTheme.bodyLarge!,
|
effectiveStyle,
|
||||||
);
|
);
|
||||||
final suggestionLines = suggestion.mapNotNull(
|
final suggestionLines = suggestion.mapNotNull(
|
||||||
(suggestion) => getTextFieldLineCount(
|
(suggestion) =>
|
||||||
textFieldKey,
|
getTextFieldLineCount(textFieldKey, suggestion, effectiveStyle),
|
||||||
suggestion,
|
|
||||||
style ?? Theme.of(context).textTheme.bodyLarge!,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return lines == 1 && suggestionLines == 1;
|
return lines == 1 && suggestionLines == 1;
|
||||||
@@ -173,13 +173,13 @@ class AutoSuggestTextField extends HookWidget {
|
|||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
text: text,
|
text: text,
|
||||||
style: (style ?? Theme.of(context).textTheme.bodyLarge)
|
style: effectiveStyle.copyWith(
|
||||||
?.copyWith(color: Colors.transparent),
|
color: Colors.transparent,
|
||||||
|
),
|
||||||
children: <TextSpan>[
|
children: <TextSpan>[
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: suggestion!.substring(text.length),
|
text: suggestion!.substring(text.length),
|
||||||
style: TextStyle(
|
style: effectiveStyle.copyWith(
|
||||||
height: 1.2,
|
|
||||||
color: Theme.of(
|
color: Theme.of(
|
||||||
context,
|
context,
|
||||||
).colorScheme.onSurfaceVariant,
|
).colorScheme.onSurfaceVariant,
|
||||||
@@ -209,7 +209,7 @@ class AutoSuggestTextField extends HookWidget {
|
|||||||
baseDecoration.floatingLabelBehavior ??
|
baseDecoration.floatingLabelBehavior ??
|
||||||
FloatingLabelBehavior.never,
|
FloatingLabelBehavior.never,
|
||||||
),
|
),
|
||||||
style: style,
|
style: effectiveStyle,
|
||||||
keyboardType: keyboardType,
|
keyboardType: keyboardType,
|
||||||
textInputAction: textInputAction,
|
textInputAction: textInputAction,
|
||||||
textCapitalization: textCapitalization,
|
textCapitalization: textCapitalization,
|
||||||
|
|||||||
Reference in New Issue
Block a user