Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Appbar's title not working on setstate in flutter

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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';
                  });
                })
          ],
        ),
      ),
    );
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading