1

When I'm trying to input text into the flutter app, I'm not able to move to the next screen and get this error. I've even looked at some other solutions to similar questions asked earlier but it's not working for me. Following is the code for the buttonbartheme class that is throwing the error.

class ButtonBarTheme extends InheritedWidget {

  /// Constructs a button bar theme that configures all descendent [ButtonBar]
  /// widgets.
  ///
  /// The [data] must not be null.

  const ButtonBarTheme({
    Key? key,
    required this.data,
    required Widget child,
  })  : assert(data != null), <- ERROR
        super(key: key, child: child);
  final ButtonBarThemeData data; 

  /// Returns the configuration [data] from the closest [ButtonBarTheme]
  /// ancestor. If there is no ancestor, it returns [ThemeData.buttonBarTheme].
  /// Applications can assume that the returned value will not be null.
  ///
  /// Typical usage is as follows:
  ///
  /// ```dart
  /// ButtonBarThemeData theme = ButtonBarTheme.of(context);
  /// ```

  static ButtonBarThemeData of(BuildContext context) {
    final ButtonBarTheme? buttonBarTheme =
        context.dependOnInheritedWidgetOfExactType<ButtonBarTheme>();
    return buttonBarTheme?.data ?? Theme.of(context).buttonBarTheme;
  }

I am using Buttonbartheme in the dashboard and other screens as follows:

ButtonBarTheme(
              // makes buttons use the appropriate styles for cards
              data: null,
              child: ButtonBar(
                children: <Widget>[
                  TextButton(
                    child: const Text('Share'),
                    onPressed: () {
                      // ignore: todo
                      //TODO Implement share to social media
                    },
                  ),
                  TextButton(
                    child: const Text('Dismiss'),
                    onPressed: () {
                      client.show1 = false;
                      update(client);
                    },
                  ),
                ],
              ),
            ),
  • Can you share the code, where you are using `ButtonBarTheme` explicitly in your code? – ibhavikmakwana Mar 28 '22 at 12:51
  • I have added the part from the dashboard screen where I am using the ButtonBarTheme. – Alyssa Anderson Mar 28 '22 at 13:26
  • You are passing null to the `data`, which is failing the assertion, It should not be null and you should pass `ButtonBarThemeData` to it. – ibhavikmakwana Mar 28 '22 at 13:29
  • 1
    I'm really new to flutter so can you tell me how do I pass ButtonBarThemeData to it because when I'm trying to replace null with ButtonBarThemeDat it's throwing an error that 'The argument type 'Type' can't be assigned to the parameter type 'ButtonBarThemeData'. – Alyssa Anderson Mar 28 '22 at 13:36

1 Answers1

0

Do:

ButtonBarTheme(
   data: ButtonBarThemeData(),
   child: //rest of code
) 
belinda.g.freitas
  • 1,016
  • 3
  • 7
  • 15
  • But why are you using `ButtonBarTheme` if you don't intend to set custom values? Just use `ButtonBar` and it will use the `MaterialApp` default theme. – belinda.g.freitas Mar 28 '22 at 16:42