Skip to content

Instantly share code, notes, and snippets.

@selvan
Last active May 14, 2024 05:34
Show Gist options
  • Save selvan/5b82baed409aa5e8cc71b90df5f4d59f to your computer and use it in GitHub Desktop.
Save selvan/5b82baed409aa5e8cc71b90df5f4d59f to your computer and use it in GitHub Desktop.
Floating bottom navbar in Dart
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(MaterialApp(home: HomePage()));
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Some Text'),
),
body: bodyContent,
extendBody: true,
bottomNavigationBar: bottomNavigationBar,
);
}
Widget get bodyContent {
return Center(child: Container(color: Colors.red));
}
Widget get bottomNavigationBar {
return Padding(
padding: EdgeInsets.all(16.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(40
),
child: BottomNavigationBar(
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: '1'),
BottomNavigationBarItem(icon: Icon(Icons.usb), label: '2'),
BottomNavigationBarItem(icon: Icon(Icons.assignment_ind), label: '3'),
BottomNavigationBarItem(icon: Icon(Icons.multiline_chart), label: '4'),
],
unselectedItemColor: Colors.grey,
selectedItemColor: Colors.black,
showUnselectedLabels: true,
),
)
);
}
}
@selvan
Copy link
Author

selvan commented May 14, 2024

Output:

Screenshot 2024-05-14 at 11 03 00 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment