Created
October 14, 2019 17:28
-
-
Save erikwco/c11e8ac10a23bb5811ea42e1211a6619 to your computer and use it in GitHub Desktop.
Flutter Communication Stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
//* *************************************** | |
//* Main | |
//* *************************************** | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Communication'), | |
); | |
} | |
} | |
//* *************************************** | |
//* HomePage Widget | |
//* *************************************** | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
// page index store | |
int _pageIndex = 0 ; | |
// page view controller | |
PageController _pageController; | |
@override | |
void initState() { | |
super.initState(); | |
_pageController = PageController(initialPage: _pageIndex); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: PageView( | |
onPageChanged: (int page) { | |
setState(() { | |
_pageIndex = page; | |
}); | |
}, | |
controller: _pageController, | |
scrollDirection: Axis.horizontal, | |
pageSnapping: true, | |
children: <Widget>[ | |
ClientInformationPage(), | |
ClientServicePage(), | |
ClientInvoicePage(), | |
], | |
) | |
), | |
bottomNavigationBar: BottomNavigationBar( | |
currentIndex: _pageIndex, | |
onTap: (int pageIndex) { | |
print(pageIndex); | |
setState(() { | |
_pageController.jumpToPage(pageIndex); | |
}); | |
}, | |
items: [ | |
BottomNavigationBarItem(title: Text('General info'), icon: Icon(Icons.info_outline,color: Colors.red)), | |
BottomNavigationBarItem(title: Text('Services'), icon: Icon(Icons.list,color: Colors.green)), | |
BottomNavigationBarItem(title: Text('Invoices'), icon: Icon(Icons.payment,color: Colors.blue)), | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () {}, | |
tooltip: 'Save', | |
child: Icon(Icons.save), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment