Home > Mobile >  Appbar's title not working on setstate in flutter
Appbar's title not working on setstate in flutter

Time:01-09

appBar: AppBar( elevation: 0.0, title: Text(gazung), backgroundColor: Color(0xffDBDDE0), ), drawer: Drawer( child: ListView( children: [

        DrawerHeader(
          decoration: BoxDecoration(
            color: Color(0xff9CA2B0),
          ),
          child: Text('2021-02 개정 기준'),
        ),

        ListTile(
          tileColor: Color(0xffDBDDE0),
          title: Text('2021-02 개정 기준'),
          onTap: (){
            setState(() {
              gazung = 'changedaapbartext';
            });

I output the title of the app bar as a variable called gazung and setstate in the drawer to change it, but it is not applied to the title of the appbar.

CodePudding user response:

You can try with this code, i did not get any issue.

class ApBarTest extends StatefulWidget {
  const ApBarTest({Key? key}) : super(key: key);

  @override
  State<ApBarTest> createState() => _ApBarTestState();
}

class _ApBarTestState extends State<ApBarTest> {
  String gazung = 'Title';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        title: Text(gazung),
        backgroundColor: Color(0xffDBDDE0),
      ),
      drawer: Drawer(
        child: ListView(
          children: [
            DrawerHeader(
              decoration: BoxDecoration(
                color: Color(0xff9CA2B0),
              ),
              child: Text('2021-02 개정 기준'),
            ),
            ListTile(
                tileColor: Color(0xffDBDDE0),
                title: Text('2021-02 개정 기준'),
                onTap: () {
                  setState(() {
                    gazung = 'changedaapbartext';
                  });
                })
          ],
        ),
      ),
    );
  }
}
  •  Tags:  
  • Related