Unscheduled appbar

Issue

I’m having trouble finding information to get my appbar up and running, can you help me?
When I click another icon the screen stays the same!
f

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';

void main() => runApp(MaterialApp(home: BottomNavBar()));

class BottomNavBar extends StatefulWidget {
  @override
  _BottomNavBarState createState() => _BottomNavBarState();

}
  bool selected = false;

class _BottomNavBarState extends State<BottomNavBar> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: CurvedNavigationBar(
        index: 0,
        height: 50.0,
        items: <Widget>[
            Icon(Icons.home, size: 30, color: Colors.white),
            Icon(Icons.camera, size: 30, color: Colors.white),
            Icon(Icons.remove_red_eye, size: 30, color: Colors.white),
        ],
        color: selected ? Colors.green.withOpacity(0.90) : Colors.red.withOpacity(0.90),
        buttonBackgroundColor: selected ? Colors.green.withOpacity(0.90) : Colors.red.withOpacity(0.90),
        backgroundColor: Colors.black12,
        animationCurve: Curves.easeInOut,
        animationDuration: Duration(
            milliseconds: 550),
      ),

Solution

Next time post some code instead of screenshot of code but it seems to me that you are missing the onTap parameter and the widget call.

try adapting your code to this small example :

class _BottomNavBarState extends State<BottomNavBar> {
  int _page = 0;
  Widget myWidgets = [WidgetA(),WidgetB()];
  GlobalKey _bottomNavigationKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        bottomNavigationBar: CurvedNavigationBar(
          key: _bottomNavigationKey,
          index: 0,
          height: 50.0,
          items: <Widget>[
            Icon(Icons.add, size: 30),
            Icon(Icons.list, size: 30),
          ],
          color: Colors.white,
          buttonBackgroundColor: Colors.white,
          backgroundColor: Colors.blueAccent,
          animationCurve: Curves.easeInOut,
          animationDuration: Duration(milliseconds: 600),
          onTap: (index) {
            setState(() {
              _page = index;
            });
          },
        ),
        body: myWidgets[_page];
  }
}

Answered By – Firas BENMBAREK

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *