Skip to content

Instantly share code, notes, and snippets.

@IshanFx
Created October 18, 2018 16:24
Show Gist options
  • Save IshanFx/6ad6e0165671286453c67f64915a4c4f to your computer and use it in GitHub Desktop.
Save IshanFx/6ad6e0165671286453c67f64915a4c4f to your computer and use it in GitHub Desktop.
Bottom navigation bar with floating button in Flutter
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Floating',
debugShowCheckedModeBanner: false,
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Float'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _cIndex = 0;
void _incrementTab(index) {
setState(() {
_cIndex = index;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
],
),
),
bottomNavigationBar:BottomNavigationBar(
currentIndex: _cIndex,
type: BottomNavigationBarType.fixed ,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home,color: Color.fromARGB(255, 0, 0, 0)),
title: new Text('Home')
),
BottomNavigationBarItem(
icon: Icon(Icons.power,color: Color.fromARGB(255, 0, 0, 0)),
title: new Text('Power')
)
],
onTap: (index){
_incrementTab(index);
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: new FloatingActionButton(
onPressed:(){ _incrementTab(1); },
tooltip: 'Increment',
child: new Icon(Icons.add),
),
);
}
}
@musindo
Copy link

musindo commented Feb 5, 2021

How do i man the selected index to navigate to a new screen

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