Describe the bug
Here is exception
======== Exception caught by widgets library =======================================================
The following _CastError was thrown building Combobox(dirty, dependencies: [MediaQuery], state: _ComboboxState#57f33):
Null check operator used on a null value
The relevant error-causing widget was:
Combobox file:///C:/Users/FengChendian/Documents/Code/Android/serialport_tool/lib/UI_components/title_combo_menu.dart:81:28
When the exception was thrown, this was the stack:
#0 FluentTheme.of (package:fluent_ui/src/styles/theme.dart:25:70)
#1 _ComboboxState._textStyle (package:fluent_ui/src/controls/form/combo_box.dart:1181:35)
#2 _ComboboxState.build (package:fluent_ui/src/controls/form/combo_box.dart:1320:13)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)
====================================================================================================
If I replace Combobox by dropdownButton, excetion will disappear.
My code is :
final values = <String>['Blue', 'Green', 'Yellow', 'Red'];
String? comboBoxValue;
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => ComboMenuDataManager(
comboBoxValue: defaultItem ?? items[0], items: items),
child: Container(
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'$title:',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
SizedBox(
width: 100,
child: Container(
padding: EdgeInsets.all(4),
child: Consumer<ComboMenuDataManager>(
builder: (_, combo, __) => SizedBox(
width: 200,
child: Combobox<String>(
// header: 'Colors',
placeholder: Text('Selected list item'),
isExpanded: true,
items: values
.map((e) => ComboboxItem<String>(
value: e,
child: Text(e),
))
.toList(),
value: comboBoxValue,
onChanged: (value) {
print(value);
// if (value != null) setState(() => comboBoxValue = value);
},
),
),
),
),
),
],
),
),
);
}
In FluentTheme.of (package:fluent_ui/src/styles/theme.dart:25:70), I found error code:
static ThemeData of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<_FluentTheme>()!.data;
}