1

I am trying to use Shell Route to make Appbar stay when changing page but having an error

so this Page is a stateful Widget with Column(children:[]) as return argument

const Register()

ShellRoute(
  navigatorKey: _shellNavigatorKey,
  builder: (context, state, childpage) {
      return Scaffold(
        appBar: AppBar(
          elevation:0,
          centerTitle:true,
          automaticallyImplyLeading: true,
          backgroundColor:const Color(0xffffffff),
          shape:const RoundedRectangleBorder(
            borderRadius:BorderRadius.zero,
          ),
          title:const Text('test',
            style:TextStyle(
              fontWeight:FontWeight.w700,
              fontStyle:FontStyle.normal,
              fontSize:18,
              color:Color(0xff000000),
            ),
          ),
          leading:IconButton(
              icon:const Icon(
                  Icons.arrow_back,
                  color:Color(0xff212435),
                  size:24,
              ),
              onPressed:
                (){
                  // GoRouter.of(context).pop();
                },
          ),
        ),
        backgroundColor: const Color(0xffffffff),
        body: Center(
          child: childpage
        )
      );
  },
  routes:<RouteBase>[
    GoRoute(
      path: '/register',
      name:'Register',
      builder: (context, state) => const Register(),
    ),
  ]
)

And this is the error I have.

enter image description here

Amirali Eric Janani
  • 1,477
  • 3
  • 10
  • 20
ralphy
  • 89
  • 1
  • 14

1 Answers1

0

To fix your error wrap your childPage with Material:

const Register()

ShellRoute(
  navigatorKey: _shellNavigatorKey,
  builder: (context, state, childpage) {
      return Scaffold(
        appBar: AppBar(
          elevation:0,
          centerTitle:true,
          automaticallyImplyLeading: true,
          backgroundColor:const Color(0xffffffff),
          shape:const RoundedRectangleBorder(
            borderRadius:BorderRadius.zero,
          ),
          title:const Text('test',
            style:TextStyle(
              fontWeight:FontWeight.w700,
              fontStyle:FontStyle.normal,
              fontSize:18,
              color:Color(0xff000000),
            ),
          ),
          leading:IconButton(
              icon:const Icon(
                  Icons.arrow_back,
                  color:Color(0xff212435),
                  size:24,
              ),
              onPressed:
                (){
                  // GoRouter.of(context).pop();
                },
          ),
        ),
        backgroundColor: const Color(0xffffffff),
        body: Material(
          child: childpage,
        ),
      );
  },
  routes:<RouteBase>[    GoRoute(      path: '/register',      name:'Register',      builder: (context, state) => const Register(),    ),  ]
)

happy coding...

Amirali Eric Janani
  • 1,477
  • 3
  • 10
  • 20