Skip to content

Instantly share code, notes, and snippets.

@mtellect
Last active April 24, 2018 14:51
Show Gist options
  • Save mtellect/cd738df6a6d40cf8e4eab20e8431e734 to your computer and use it in GitHub Desktop.
Save mtellect/cd738df6a6d40cf8e4eab20e8431e734 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'screens/style.dart';
import 'screens/home/home.dart';
import 'screens/gallery/gallery.dart';
import 'screens/settings/settings.dart';
class MyApp extends StatefulWidget {
@override
MyAppState createState() {
return new MyAppState();
}
}
class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
static const platform = const MethodChannel('com.examples.lessonone/battery');
TabController tabController;
PageController pageController;
TabItem _tabHandler;
var _title_app = null;
int _tab = 0;
@override
void initState() {
// TODO: implement initState
super.initState();
pageController = new PageController();
tabController = new TabController(
length: 3,
vsync: this,
initialIndex: 0,
);
_tabHandler = TabItems[0];
tabController.addListener(listenerForTabChange);
this._title_app = TabItems[0].title;
}
@override
void dispose() {
pageController.dispose();
tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
//TODO: implement build
return new Scaffold(
appBar: new AppBar(
title: new Text(_tabHandler.title),
//new Text('Dailies Food'),
backgroundColor: appColor,
bottom: new TabBar(
controller: tabController,
indicatorColor: Colors.white,
tabs: <Tab>[
new Tab(icon: new Icon(TabItems[0].icon)),
new Tab(icon: new Icon(TabItems[1].icon)),
new Tab(icon: new Icon(TabItems[2].icon)),
],
),
actions: <Widget>[
new Icon(Icons.search),
new Padding(padding: const EdgeInsets.symmetric(horizontal: 5.0)),
new Icon(Icons.more_vert)
],
),
body: new TabBarView(
controller: tabController,
children: <Widget>[
new HomePage(),
new GalleryPage(),
new SettingsPage()
],
),
);
}
// Get battery level.
String _batteryLevel = 'Unknown battery level.';
Future<String> _getBatteryLevel() async {
String batteryLevel;
try {
final int result = await platform.invokeMethod('getBatteryLevel');
batteryLevel = 'Battery level at $result % ';
} on PlatformException catch (e) {
batteryLevel = "Failed to get battery level: '${e.message}'.";
}
return batteryLevel;
}
void onTabChanged(int tab) {
setState(() {
this._tab = tab;
this._title_app = TabItems[tab].title;
print(_title_app);
});
}
void listenerForTabChange() {
onTabChanged(tabController.index);
setState(() {
_tabHandler = TabItems[tabController.index];
});
}
}
class TabItem {
const TabItem({this.title, this.icon});
final String title;
final IconData icon;
}
const List<TabItem> TabItems = const <TabItem>[
const TabItem(title: 'Home', icon: Icons.home),
const TabItem(title: 'Gallery', icon: Icons.image),
const TabItem(title: 'Settings', icon: Icons.settings)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment