@lvfarias/fl-cli
Version:
Flutter CLI
95 lines (84 loc) • 2.23 kB
JavaScript
const content = `import 'package:{APP_NAME}/pages/home/page.dart';
import 'package:{APP_NAME}/pages/about/page.dart';
import 'package:{APP_NAME}/pages/profile/page.dart';
import 'package:{APP_NAME}/themes/colors.dart';
import 'package:flutter/material.dart';
class TabsPage extends StatefulWidget {
final int index;
TabsPage({Key key, this.index}) : super(key: key);
_TabsPageState createState() => _TabsPageState(index: this.index);
}
class _TabsPageState extends State<TabsPage> with TickerProviderStateMixin {
final int index;
int _currentPageIndex = 0;
List<Widget> _tabList = [
homePage,
aboutPage,
profilePage,
];
TabController _tabController;
_TabsPageState({Key key, this.index});
_changeTabIndex() {
if (_currentPageIndex != _tabController.index) {
setState(() {
_currentPageIndex = _tabController.index;
});
}
}
_tapOnTab(index) {
setState(() {
_currentPageIndex = index;
});
_tabController.animateTo(_currentPageIndex);
}
void initState() {
super.initState();
_currentPageIndex = this.index;
_tabController = TabController(
vsync: this,
length: 3,
);
_tabController.addListener(_changeTabIndex);
}
void dispose() {
_tabController.dispose();
_tabController.removeListener(_changeTabIndex);
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('App'),
),
body: TabBarView(
controller: _tabController,
children: _tabList,
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentPageIndex,
selectedItemColor: AppColors.primary,
onTap: _tapOnTab,
items: [
BottomNavigationBarItem(
title: Text('Home'),
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
title: Text('About'),
icon: Icon(Icons.info),
),
BottomNavigationBarItem(
title: Text('Profile'),
icon: Icon(Icons.person),
),
],
),
);
}
}
`;
module.exports = content;