I am having a few issues after migrating to flutter null-safety. I have a data type bool _isLoading = false;
I'm getting an error after migrating to null-safety in my code: The return type 'Null' isn't a 'Widget', as required by the closure's context
class _PlacesState extends State<_Places> {
bool _isLoading = false;
final TextEditingController _typeAheadController = TextEditingController();
@override
Widget build(BuildContext context) {
return TypeAheadFormField<Map<String, dynamic>>(
key: widget.formFieldKey,
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,
decoration: InputDecoration(
hintText: 'Place',
contentPadding: EdgeInsets.only(left: 8, right: 8),
border: InputBorder.none,
),
controller: _typeAheadController,
),
suggestionsCallback: (String? pattern) async {
final s = pattern?.trim();
if (s == null || s == '' || s.length < 4) return null;
_isLoading = true;
try {
await Future.delayed(Duration(seconds: 1));
final data = await (_request(s) as FutureOr<Map<String, dynamic>>);
final result = data['hits'] as List;
return result.cast<Map<String, dynamic>>();
} finally {
_isLoading = false;
}
} as FutureOr<Iterable<Map<String, dynamic>>> Function(String),
loadingBuilder: (BuildContext context) {
if (!_isLoading) return null;
return Align(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: ExtendedProgressIndicator(),
),
);
},
This is where I get the error if (!_isLoading) return null;
as FutureOr<Iterable<Map<String, dynamic>>> Function(String),
loadingBuilder: (BuildContext context) {
if (!_isLoading) return null;
return Align(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: ExtendedProgressIndicator(),
),
);
},
loadingBuilder
should return a Widget
if you want this line if (!_isLoading) return null;
to return a whitespace just do something like this if (!_isLoading) return SizedBox();