Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

android - I want to change the appbar's title of the pages with respect to the curved navigation bar's tab

I am implementing curved navigation bar in my flutter project. But I can't recognise why the data is not passing to the second page(i.e. notification.dart page). The same data is showing in the first page(i.e. home.dart page) but not in the second page(i.e. notification.dart page)

Here is my code:

Appbar's code:

Widget aapBarSection(String title, Color color, BuildContext context){
    return AppBar(
      title: Text(title, style:TextStyle(fontFamily: 'Poppins-Regular'), ),
      centerTitle: true,
      backgroundColor: color,
      actions: [
        FlatButton(
          child: Text('Logout', style: TextStyle(color: Colors.white)),
          onPressed: () async{
            SharedPreferences preferences = await SharedPreferences.getInstance();
            preferences.setBool("isLogin", false);
            Navigator.of(context).pushNamed('/login');
          },
        )
      ],
      leading: IconButton(
        icon: Icon(Icons.arrow_back),
        onPressed: (){
          exit(0);
        },
      ),
    );
  }

NavigationBar's code:

int currentIndex = 0;
  Widget navBarSection(Color color, Color btnColor){
    return CurvedNavigationBar(
      index: 0,
      items:
      [
        Icon(Icons.home, color: Colors.white),
        Icon(Icons.notifications, color: Colors.white),
        Icon(Icons.menu, color: Colors.white),
        Icon(Icons.history, color: Colors.white),
        Icon(Icons.person, color: Colors.white),
      ],
      color: color,
      buttonBackgroundColor: btnColor,
      animationCurve: Curves.easeInOut,
      animationDuration: Duration(milliseconds: 600),
      onTap: (index){
        setState(() {
          currentIndex = index;
        });
      },
    );
  }


  void setState(Null Function() param0) {

  }

home.dart code:

import 'package:thehelpdesk/widgets/appbar.dart';
import 'package:thehelpdesk/widgets/navigation_bar.dart';
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: aapBarSection('Home',Colors.blueAccent[700],context),
      bottomNavigationBar: navBarSection(
        Colors.blueAccent[700],
        Colors.blueAccent[700],
    ),
      body: Container(
        color: Colors.grey,
        child: Text('abcd', style: TextStyle(
            fontSize: 50,
            color: Colors.black
        ),),
      ),
    );
  }
}

notification.dart code:

import 'package:thehelpdesk/widgets/appbar.dart';
import 'package:thehelpdesk/widgets/navigation_bar.dart';

class NotificationPage extends StatefulWidget {
  @override
  _NotificationPageState createState() => _NotificationPageState();
}

class _NotificationPageState extends State<NotificationPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: aapBarSection('Notification',Colors.blueAccent[700],context),
      bottomNavigationBar: navBarSection(
        Colors.blueAccent[700],
        Colors.blueAccent[700],
      ),
      body: Container(
        color: Colors.grey,
        child: Text('abcd', style: TextStyle(
          fontSize: 50,
          color: Colors.black
        ),),
      ),
    );
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...