0

I'm currently developing with Flutter, using VS Code as my compiler and Pixel 6 as my simulator, with Android SDK 34. I've encountered an issue where my application's navigator (bottom gesture bar) shows a black border. Here's the code I'm using, derived from the official Flutter docs under the 'navigation bar' section:

flutter create --sample=material.NavigationBar.1 mysample 
import 'package:flutter/material.dart';

/// Flutter code sample for [NavigationBar].

void main() => runApp(const NavigationBarApp());

class NavigationBarApp extends StatelessWidget {
  const NavigationBarApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: NavigationExample());
  }
}

class NavigationExample extends StatefulWidget {
  const NavigationExample({super.key});

  @override
  State<NavigationExample> createState() => _NavigationExampleState();
}

class _NavigationExampleState extends State<NavigationExample> {
  int currentPageIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: NavigationBar(
        onDestinationSelected: (int index) {
          setState(() {
            currentPageIndex = index;
          });
        },
        selectedIndex: currentPageIndex,
        destinations: const <Widget>[
          NavigationDestination(
            icon: Icon(Icons.explore),
            label: 'Explore',
          ),
          NavigationDestination(
            icon: Icon(Icons.commute),
            label: 'Commute',
          ),
          NavigationDestination(
            selectedIcon: Icon(Icons.bookmark),
            icon: Icon(Icons.bookmark_border),
            label: 'Saved',
          ),
        ],
      ),
      body: <Widget>[
        Container(
          color: Colors.red,
          alignment: Alignment.center,
          child: const Text('Page 1'),
        ),
        Container(
          color: Colors.green,
          alignment: Alignment.center,
          child: const Text('Page 2'),
        ),
        Container(
          color: Colors.blue,
          alignment: Alignment.center,
          child: const Text('Page 3'),
        ),
      ][currentPageIndex],
    );
  }
}

Expected Result: I am trying to achieve this look on my navigation bar, there is no extra black board under the navigation bar: Expected Result

Actual Result: But the app is currently showing a black border on the navigation bar like so: Actual Result

I've tried:

  1. Other example code from the official Flutter docs.
  2. Other simulator like Pixel 5 and resizable simulator.
  3. Other SDK like Android 13 or Android 12.

but the issue still persists.

ljhao24
  • 11

3 Answers3

2

You will need to update your setSystemUIOverlayStyle, take a look at the Link

You can see the example there.

Also more info here:

Source 1 Source 2

Vivek Chib
  • 837
  • 1
  • 2
  • 13
Sailesh Dahal
  • 159
  • 1
  • 9
  • Thanks, I can set the color to red or blue or anything with `setSystemUIOverlayStyle` ,but how can I make the color exactly same as the default color of navigation bar and change along side when the navigation bar color changes ( for example, I use dynamic color and the navigation bar color is changed according to the theme) – ljhao24 Aug 01 '23 at 06:20
  • If you want to change the navigation bar based on the screen, you will have to do it through the AnnotatedRegion https://stackoverflow.com/a/51013116/9611399 – Sailesh Dahal Aug 01 '23 at 10:18
0

Use systemChrome Function for that

just put this code in either in initState()

SystemChrome.setSystemUIOverlayStyle(
      const SystemUiOverlayStyle(
          statusBarColor: Colors.transparent,
          systemNavigationBarColor: Colors.white
      ),
);
amit.flutter
  • 883
  • 9
  • 27
  • 1
    you can call it in main() method. It will still work. – Vivek Chib Aug 01 '23 at 05:20
  • I've tried this and now the black bar become white bar, still slightly different form the navigation bar color: [like this](https://i.imgur.com/Loo1WmC.png) – ljhao24 Aug 01 '23 at 06:00
  • Also I use `systemNavigationBarColor:Colors.transparent` still the same. – ljhao24 Aug 01 '23 at 06:06
  • make color white. or you can work arround other property as well. – amit.flutter Aug 01 '23 at 06:23
  • Thanks, I can set the color to white or red or blue or anything with setSystemUIOverlayStyle ,but is there a way to make the color exactly same as the color of navigation bar and change along side when the navigation bar color changes? ( for example, I use dynamic color and the navigation bar color is changed according to the theme) – ljhao24 Aug 01 '23 at 06:31
  • as per my knowledge, you have to set color manually in all screens either pre-define or from API. – amit.flutter Aug 01 '23 at 06:50
0

Here's an code that sets a transparent navigation bar and system UI overlay:

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Set the system UI overlay to transparent navigation bar.
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      systemNavigationBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.light,
      statusBarBrightness: Brightness.dark,
    ));

    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My App'),
      ),
      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',
          ),
        ],
      ),
      body: Center(
        child: Text('Hello, World!'),
      ),
    );
  }
}

To achieve a transparent navigation bar, you can try using the SystemUiOverlayStyle.light for the status bar icons and text color. Additionally, you can set the navigation bar color to Colors.transparent and set its brightness to Brightness.dark.