Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added itemSeparatorBuilder, Removed top padding on scrollbar, Added autofillHints properties #489

Merged
merged 3 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions analysis_options.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
10 changes: 5 additions & 5 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.10'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
55 changes: 42 additions & 13 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class _MyAppState extends State<MyApp> {
if (!isCupertino) {
return MaterialApp(
title: 'flutter_typeahead demo',
scrollBehavior:
MaterialScrollBehavior().copyWith(dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch}),
scrollBehavior: MaterialScrollBehavior().copyWith(
dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch}),
home: DefaultTabController(
length: 3,
child: Scaffold(
Expand Down Expand Up @@ -85,9 +85,14 @@ class NavigationExample extends StatelessWidget {
),
TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
autofillHints: ["AutoFillHints 1", "AutoFillHints 2"],
autofocus: true,
style: DefaultTextStyle.of(context).style.copyWith(fontStyle: FontStyle.italic),
decoration: InputDecoration(border: OutlineInputBorder(), hintText: 'What are you looking for?'),
style: DefaultTextStyle.of(context)
.style
.copyWith(fontStyle: FontStyle.italic),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'What are you looking for?'),
),
suggestionsCallback: (pattern) async {
return await BackendService.getSuggestions(pattern);
Expand All @@ -99,9 +104,12 @@ class NavigationExample extends StatelessWidget {
subtitle: Text('\$${suggestion['price']}'),
);
},
itemSeparatorBuilder: (context, index) {
return Divider();
},
onSuggestionSelected: (Map<String, String> suggestion) {
Navigator.of(context)
.push<void>(MaterialPageRoute(builder: (context) => ProductPage(product: suggestion)));
Navigator.of(context).push<void>(MaterialPageRoute(
builder: (context) => ProductPage(product: suggestion)));
},
suggestionsBoxDecoration: SuggestionsBoxDecoration(
borderRadius: BorderRadius.circular(10.0),
Expand Down Expand Up @@ -159,14 +167,18 @@ class _FormExampleState extends State<FormExample> {
title: Text(suggestion),
);
},
itemSeparatorBuilder: (context, index) {
return Divider();
},
transitionBuilder: (context, suggestionsBox, controller) {
return suggestionsBox;
},
onSuggestionSelected: (String suggestion) {
this._typeAheadController.text = suggestion;
},
suggestionsBoxController: suggestionBoxController,
validator: (value) => value!.isEmpty ? 'Please select a city' : null,
validator: (value) =>
value!.isEmpty ? 'Please select a city' : null,
onSaved: (value) => this._selectedCity = value,
),
Spacer(),
Expand All @@ -177,7 +189,8 @@ class _FormExampleState extends State<FormExample> {
this._formKey.currentState!.save();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Your Favorite City is ${this._selectedCity}'),
content: Text(
'Your Favorite City is ${this._selectedCity}'),
),
);
}
Expand Down Expand Up @@ -238,16 +251,24 @@ class ScrollExample extends StatelessWidget {
TypeAheadField<String>(
getImmediateSuggestions: true,
textFieldConfiguration: TextFieldConfiguration(
decoration: InputDecoration(border: OutlineInputBorder(), hintText: 'What are you looking for?'),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'What are you looking for?'),
),
suggestionsCallback: (String pattern) async {
return items.where((item) => item.toLowerCase().startsWith(pattern.toLowerCase())).toList();
return items
.where((item) =>
item.toLowerCase().startsWith(pattern.toLowerCase()))
.toList();
},
itemBuilder: (context, String suggestion) {
return ListTile(
title: Text(suggestion),
);
},
itemSeparatorBuilder: (context, index) {
return Divider();
},
onSuggestionSelected: (String suggestion) {
print("Suggestion selected");
},
Expand All @@ -265,7 +286,10 @@ class BackendService {
await Future<void>.delayed(Duration(seconds: 1));

return List.generate(3, (index) {
return {'name': query + index.toString(), 'price': Random().nextInt(100).toString()};
return {
'name': query + index.toString(),
'price': Random().nextInt(100).toString()
};
});
}
}
Expand Down Expand Up @@ -305,7 +329,8 @@ class FavoriteCitiesPage extends StatefulWidget {
class _FavoriteCitiesPage extends State<FavoriteCitiesPage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _typeAheadController = TextEditingController();
CupertinoSuggestionsBoxController _suggestionsBoxController = CupertinoSuggestionsBoxController();
CupertinoSuggestionsBoxController _suggestionsBoxController =
CupertinoSuggestionsBoxController();
String favoriteCity = 'Unavailable';

@override
Expand Down Expand Up @@ -347,10 +372,14 @@ class _FavoriteCitiesPage extends State<FavoriteCitiesPage> {
),
);
},
itemSeparatorBuilder: (context, index) {
return Divider();
},
onSuggestionSelected: (String suggestion) {
_typeAheadController.text = suggestion;
},
validator: (value) => value!.isEmpty ? 'Please select a city' : null,
validator: (value) =>
value!.isEmpty ? 'Please select a city' : null,
),
SizedBox(
height: 10.0,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.12.0-0 <3.0.0"
sdk: ">=2.19.0 <3.0.0"

dependencies:
flutter:
Expand Down
157 changes: 80 additions & 77 deletions lib/src/cupertino/field/cupertino_text_field_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,86 +67,87 @@ class CupertinoTextFieldConfiguration {
final Brightness? keyboardAppearance;
final EdgeInsets scrollPadding;
final bool enableInteractiveSelection;
final List<String>? autofillHints;

/// Creates a CupertinoTextFieldConfiguration
const CupertinoTextFieldConfiguration({
this.controller,
this.focusNode,
this.decoration = _kDefaultRoundedBorderDecoration,
this.padding = const EdgeInsets.all(6.0),
this.placeholder,
this.placeholderStyle,
this.prefix,
this.prefixMode = OverlayVisibilityMode.always,
this.suffix,
this.suffixMode = OverlayVisibilityMode.always,
this.clearButtonMode = OverlayVisibilityMode.never,
this.keyboardType,
this.textInputAction,
this.textCapitalization = TextCapitalization.none,
this.style,
this.textAlign = TextAlign.start,
this.autofocus = false,
this.obscureText = false,
this.autocorrect = true,
this.maxLines = 1,
this.minLines,
this.maxLength,
this.maxLengthEnforcement,
this.onChanged,
this.onEditingComplete,
this.onTap,
this.onSubmitted,
this.inputFormatters,
this.enabled = true,
this.enableSuggestions = true,
this.cursorWidth = 2.0,
this.cursorRadius = const Radius.circular(2.0),
this.cursorColor,
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
this.enableInteractiveSelection = true,
});
const CupertinoTextFieldConfiguration(
{this.controller,
this.focusNode,
this.decoration = _kDefaultRoundedBorderDecoration,
this.padding = const EdgeInsets.all(6.0),
this.placeholder,
this.placeholderStyle,
this.prefix,
this.prefixMode = OverlayVisibilityMode.always,
this.suffix,
this.suffixMode = OverlayVisibilityMode.always,
this.clearButtonMode = OverlayVisibilityMode.never,
this.keyboardType,
this.textInputAction,
this.textCapitalization = TextCapitalization.none,
this.style,
this.textAlign = TextAlign.start,
this.autofocus = false,
this.obscureText = false,
this.autocorrect = true,
this.maxLines = 1,
this.minLines,
this.maxLength,
this.maxLengthEnforcement,
this.onChanged,
this.onEditingComplete,
this.onTap,
this.onSubmitted,
this.inputFormatters,
this.enabled = true,
this.enableSuggestions = true,
this.cursorWidth = 2.0,
this.cursorRadius = const Radius.circular(2.0),
this.cursorColor,
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
this.enableInteractiveSelection = true,
this.autofillHints});

/// Copies the [CupertinoTextFieldConfiguration] and only changes the specified properties
CupertinoTextFieldConfiguration copyWith({
TextEditingController? controller,
FocusNode? focusNode,
BoxDecoration? decoration,
EdgeInsetsGeometry? padding,
String? placeholder,
TextStyle? placeholderStyle,
Widget? prefix,
OverlayVisibilityMode? prefixMode,
Widget? suffix,
OverlayVisibilityMode? suffixMode,
OverlayVisibilityMode? clearButtonMode,
TextInputType? keyboardType,
TextInputAction? textInputAction,
TextCapitalization? textCapitalization,
TextStyle? style,
TextAlign? textAlign,
bool? autofocus,
bool? obscureText,
bool? autocorrect,
int? maxLines,
int? minLines,
int? maxLength,
MaxLengthEnforcement? maxLengthEnforcement,
ValueChanged<String>? onChanged,
VoidCallback? onEditingComplete,
GestureTapCallback? onTap,
ValueChanged<String>? onSubmitted,
List<TextInputFormatter>? inputFormatters,
bool? enabled,
bool? enableSuggestions,
double? cursorWidth,
Radius? cursorRadius,
Color? cursorColor,
Brightness? keyboardAppearance,
EdgeInsets? scrollPadding,
bool? enableInteractiveSelection,
}) {
CupertinoTextFieldConfiguration copyWith(
{TextEditingController? controller,
FocusNode? focusNode,
BoxDecoration? decoration,
EdgeInsetsGeometry? padding,
String? placeholder,
TextStyle? placeholderStyle,
Widget? prefix,
OverlayVisibilityMode? prefixMode,
Widget? suffix,
OverlayVisibilityMode? suffixMode,
OverlayVisibilityMode? clearButtonMode,
TextInputType? keyboardType,
TextInputAction? textInputAction,
TextCapitalization? textCapitalization,
TextStyle? style,
TextAlign? textAlign,
bool? autofocus,
bool? obscureText,
bool? autocorrect,
int? maxLines,
int? minLines,
int? maxLength,
MaxLengthEnforcement? maxLengthEnforcement,
ValueChanged<String>? onChanged,
VoidCallback? onEditingComplete,
GestureTapCallback? onTap,
ValueChanged<String>? onSubmitted,
List<TextInputFormatter>? inputFormatters,
bool? enabled,
bool? enableSuggestions,
double? cursorWidth,
Radius? cursorRadius,
Color? cursorColor,
Brightness? keyboardAppearance,
EdgeInsets? scrollPadding,
bool? enableInteractiveSelection,
List<String>? autofillHints}) {
return CupertinoTextFieldConfiguration(
controller: controller ?? this.controller,
focusNode: focusNode ?? this.focusNode,
Expand Down Expand Up @@ -183,7 +184,9 @@ class CupertinoTextFieldConfiguration {
cursorColor: cursorColor ?? this.cursorColor,
keyboardAppearance: keyboardAppearance ?? this.keyboardAppearance,
scrollPadding: scrollPadding ?? this.scrollPadding,
enableInteractiveSelection: enableInteractiveSelection ?? this.enableInteractiveSelection,
enableInteractiveSelection:
enableInteractiveSelection ?? this.enableInteractiveSelection,
autofillHints: autofillHints ?? this.autofillHints,
);
}
}
Loading