main.dart
import 'package:flutter/material.dart';
import 'tabbar.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Navigation',
initialRoute: '/',
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => Home(),
// '/search': (BuildContext context) => SearchBarDemo(),
// '/scrollMap': (BuildContext context) => scrollMap(),
},
);
}
}
tabbar.dart
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int _currentIndex = 0;
final List<Widget> _children = [
new HomePage(),
new Profile(),
new Profile(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _children[_currentIndex],
bottomNavigationBar: new BottomNavigationBar(
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text('Home'),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.person),
title: new Text('Profile'),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.backup),
title: new Text('pro'),
),
],
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Home'),
),
body: new Center(
child: new Container( // gray box
child: new Center(
child: new Transform(
child: new RaisedButton( // red box
child: new Text(
"super man",
style: new TextStyle(
color: Colors.red,
fontSize: 24.0,
fontWeight: FontWeight.w900,
),
textAlign: TextAlign.center,
),
padding: new EdgeInsets.all(16.0),
color: Colors.blue,
onPressed: () {
// Navigator.of(context).pushNamed('/scrollMap');
},
),
alignment: Alignment.center,
transform: new Matrix4.identity()
..rotateZ(15 * 3.1415927 / 180),
),
),
width: 320.0,
height: 240.0,
color: Colors.grey[300],
),
),
);
}
}
class Profile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Profiles'),
),
body: Center(
child: RaisedButton(
child: Text('search'),
onPressed: () {
// Navigator.of(context).pushNamed('/search');
},
),
),
);
}
}