Last active
March 28, 2022 01:47
-
-
Save jetobe95/6643c2a3fd06381a586ccf50ce9539c5 to your computer and use it in GitHub Desktop.
CupertinoSegmentedControl
This file contains 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
// main.dart | |
import 'package:flutter/cupertino.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoApp( | |
// Remove the debug banner | |
debugShowCheckedModeBanner: false, | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
String? _selectedValue; | |
@override | |
Widget build(BuildContext context) { | |
// Lista de tipos | |
List<String> fastFood = ["Pizza", "Burger", "Sandwich"]; | |
final children = fastFood.asMap().map( | |
(key, value) => MapEntry( | |
key.toString(), | |
Text(value), | |
), | |
); | |
return CupertinoPageScaffold( | |
navigationBar: const CupertinoNavigationBar( | |
middle: Text('Title'), | |
), | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
CupertinoSegmentedControl( | |
// Usamos el children aqui1 | |
children: children, | |
onValueChanged: (String value) { | |
setState(() { | |
_selectedValue = value; | |
}); | |
}, | |
), | |
const SizedBox(height: 30), | |
_selectedValue != null | |
? Text( | |
_selectedValue!, | |
style: TextStyle(fontSize: 50), | |
) | |
: Container() | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment