Issues with Cupertino Navigation Bar

Issue

I am trying to create a custom CupertinoNavigationBar but I keep getting errors related to ObstructingPreferredSizeWidget. Can someone tell me what I need to implement to fix this? The error message I am getting is:

Missing concrete implementation of ‘ObstructingPreferredSizeWidget.shouldFullyObstruct’. Try implementing the missing method, or make the class abstract.

Here is the class for my CupertinoNavigationBar:

class CupertinoTopBar extends StatelessWidget
    implements ObstructingPreferredSizeWidget {
        Size preferredSize = Size.fromHeight(kToolbarHeight);

  @override
  Widget build(BuildContext context) {
    return CupertinoNavigationBar(
      leading: Text('AUC_CS'),
      backgroundColor: CupertinoTheme.of(context).primaryColor,
    );
  }
}

Solution

If you implement ObstructingPreferredSizeWidget you have to implement the following methods:

  @override
  // TODO: implement preferredSize
  Size get preferredSize => throw UnimplementedError();

  @override
  bool shouldFullyObstruct(BuildContext context) {
    // TODO: implement shouldFullyObstruct
    throw UnimplementedError();
  }

Answered By – 0x4b50

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *