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:
- Other example code from the official Flutter docs.
- Other simulator like Pixel 5 and resizable simulator.
- Other SDK like Android 13 or Android 12.
but the issue still persists.
3
Answers
Use systemChrome Function for that
just put this code in either in initState()
You will need to update your
setSystemUIOverlayStyle
, take a look at the linkhttps://api.flutter.dev/flutter/services/SystemChrome/setSystemUIOverlayStyle.html.
You can see the example there.
Also more info here.
Flutter: Where should I call SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark)
https://medium.com/@mustafatahirhussein/these-quick-tips-will-surely-help-you-to-build-a-better-flutter-app-6db93c1095b6
Here’s an code that sets a transparent navigation bar and system UI overlay:
By setting
SystemChrome.setSystemUIOverlayStyle
with a transparentsystemNavigationBarColor
, you should be able to remove the black border around the bottom navigation bar on your Pixel 6 simulator.