skip to Main Content

enter image description here

I’m not sure what this shadow/highlight effect is called but how do I remove this?

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: child,
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: 'Feed',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.groups),
            label: 'Groups',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person),
            label: 'Profile',
          ),
        ],
        currentIndex: _calculateSelectedIndex(context),
        onTap: (int idx) => _onItemTapped(idx, context),
        elevation: 0,
      ),
    );
  }

This is my code right now

3

Answers


  1. The BottomNavigationBarItem is not a widget but more of a container class which BottomNavigationBar needs for the items inside it.

    So you will need to override BottomNavigationBar and you can create your own CustomBottomNavigationBar

    Login or Signup to reply.
  2. Wrap your BottomNavigationBar() with Theme() and provide ThemeData.

    bottomNavigationBar: Theme(
          data: ThemeData(
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
          ),
          child: BottomNavigationBar(
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: 'Feed',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.groups),
                label: 'Groups',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.person),
                label: 'Profile',
              ),
            ],
            currentIndex: index,
            onTap: (value) {
              setState(() {
                index = value;
              });
            },
            elevation: 0,
          ),
        ),
    
    Login or Signup to reply.
  3. To disable the splash color effect in the BottomNavigationBar, you can override the splash color in the theme of your app to be transparent. Here’s how you can do it

    import 'package:flutter/material.dart';
    
    void main() => runApp(const BottomNavigationBarExampleApp());
    
    class BottomNavigationBarExampleApp extends StatelessWidget {
      const BottomNavigationBarExampleApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData(
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
          ),
          home: BottomNavigationBarExample(),
        );
      }
    }
    
    class BottomNavigationBarExample extends StatefulWidget {
      const BottomNavigationBarExample({super.key});
    
      @override
      State<BottomNavigationBarExample> createState() =>
          _BottomNavigationBarExampleState();
    }
    
    class _BottomNavigationBarExampleState
        extends State<BottomNavigationBarExample> {
      int _selectedIndex = 0;
      static const TextStyle optionStyle =
          TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
      static const List<Widget> _widgetOptions = <Widget>[
        Text(
          'Index 0: Home',
          style: optionStyle,
        ),
        Text(
          'Index 1: Business',
          style: optionStyle,
        ),
        Text(
          'Index 2: School',
          style: optionStyle,
        ),
      ];
    
      void _onItemTapped(int index) {
        setState(() {
          _selectedIndex = index;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('BottomNavigationBar Sample'),
          ),
          body: Center(
            child: _widgetOptions.elementAt(_selectedIndex),
          ),
          bottomNavigationBar: BottomNavigationBar(
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Icon(Icons.home),
                label: 'Home',
                
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.business),
                label: 'Business',
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.school),
                label: 'School',
              ),
            ],
            currentIndex: _selectedIndex,
            selectedItemColor: Colors.amber[800],
            onTap: _onItemTapped,
          ),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search