Created
May 7, 2020 17:40
-
-
Save iampato/4778ccf6f396cdd3d83fe350ec575d10 to your computer and use it in GitHub Desktop.
cupertinosegmentedcontrol
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/cupertino.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: HomeScreen(), | |
), | |
); | |
} | |
class HomeScreen extends StatefulWidget { | |
@override | |
_HomeScreenState createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> | |
with SingleTickerProviderStateMixin { | |
TabController _tabController; | |
final Map<int, Widget> pages = const <int, Widget>{ | |
0: Text("Symptoms"), | |
1: Text("Prevention"), | |
}; | |
int currentIndex = 0; | |
@override | |
void initState() { | |
_tabController = new TabController(length: 2, vsync: this); | |
_tabController.addListener(() { | |
setState(() { | |
currentIndex = _tabController.index; | |
}); | |
}); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Column( | |
children: <Widget>[ | |
PreferredSize( | |
preferredSize: const Size.fromHeight(48.0), | |
child: CupertinoSegmentedControl( | |
children: pages, | |
groupValue: currentIndex, | |
onValueChanged: (int val) { | |
setState( | |
() { | |
this._tabController.index = val; | |
}, | |
); | |
}, | |
), | |
), | |
Expanded( | |
child: TabBarView( | |
controller: _tabController, | |
children: <Widget>[ | |
ListView.builder( | |
itemCount: 20, | |
itemBuilder: (context, i) { | |
return Text("$i"); | |
}, | |
), | |
Text("Page 2"), | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment