Home > Net >  Flutter AppBar IconButton Navigation
Flutter AppBar IconButton Navigation

Time:12-09

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBar(),
      backgroundColor: Colors.white,
      body: Body(),
    );
  }




  AppBar buildAppBar() {

      return AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        leading: IconButton(
          padding: EdgeInsets.only(left: kDefaultPadding),
          icon: SvgPicture.asset("assets/icons/menu.svg"),
          onPressed: () {},
        ),
        actions: <Widget>[
          Container(
            width: 200,
            alignment: Alignment(-0.4, 0.0),
            child: Text('JOA',
              textAlign: TextAlign.center,
              style:
              TextStyle(
                color: kTextColor,
                fontSize: 33,
              ),
            ),
          ),
          IconButton(
            padding: EdgeInsets.symmetric(horizontal: kDefaultPadding),
            icon: SvgPicture.asset("assets/icons/logon.svg"),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (BuildContext context) => WelcomeScreen(),
                ),
              );
            },
          ),

        ],
      );

  }
}

Here Error code

lib/home/home_screen.dart:47:17: Error: The getter 'context' isn't defined for the class 'HomeScreen'.

  • 'HomeScreen' is from 'package:movie_app/home/home_screen.dart' ('lib/home/home_screen.dart').

Try correcting the name to the name of an existing getter, or defining a getter or field named 'context'. context,

How can add context after Appbar

CodePudding user response:

In your Scaffold :

appBar: buildAppBar(context),

Then in your Appbar Widget :

AppBar buildAppBar(BuildContext context) 
  • Related