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

🐛 Null check operator used on a null value When using Combobox #46

Closed
FengChendian opened this issue Jun 19, 2021 · 5 comments
Closed

Comments

@FengChendian
Copy link

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;
  }
@bdlukaa
Copy link
Owner

bdlukaa commented Jun 20, 2021

Are you using the FluentApp??

@FengChendian
Copy link
Author

Oh my god... I thought it was just a non-essential component about setting style. It works well after using FluentApp.

Maybe documention should emphasize using it😂
Thanks for help!

@bdlukaa
Copy link
Owner

bdlukaa commented Jun 20, 2021

Oh my god... I thought it was just a non-essential component about setting style.

Almost every widget provided by this lib uses FluentTheme.of(context). There must be a FluentApp or a FluentTheme above all these widgets.

@ntwarijoshua
Copy link

@bdlukaa Am mixing Material with Fluent be able to use some of the components in fluent. i have wrapped them with FluentTheme. but i still get this error ```The following _CastError was thrown building _TooltipOverlay(dirty):
Null check operator used on a null value



This is the code

fluent.FluentTheme(
data: fluent.ThemeData(),
child: fluent.Localizations(
locale: const fluent.Locale.fromSubtags(languageCode: 'en'),
delegates: const [
fluent.DefaultFluentLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
child: SizedBox(
```

      Any ideas?

@bdlukaa
Copy link
Owner

bdlukaa commented Aug 24, 2022

@ntwarijoshua I need more info about your issue! What version are you using? Can you share a reproducible snippet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants