Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class minumanFav extends StatefulWidget {
- int radioGroupValue = 0;
- @override
- State<minumanFav> createState() => _minumanFavState();
- }
- class _minumanFavState extends State<minumanFav> {
- int _radioGroupValue = 0;
- String _selectedFavorite = "";
- List<String> _favoriteList = [];
- @override
- void initState(){
- super.initState();
- _favoriteList..add('Jus Kulit Durian')..add('Es Kelapa Bakar')..add('Susu Kukus');
- _radioGroupValue = widget.radioGroupValue;
- _selectedFavorite = _favoriteList[widget.radioGroupValue];
- }
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("Minuman Favorite"),
- actions: [
- IconButton(
- icon: Icon(Icons.check),
- onPressed: (){
- Navigator.pop(context, _selectedFavorite);
- },
- )
- ],
- ),
- body: SafeArea(
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(children: [
- Radio(
- value : 0,
- groupValue: _radioGroupValue,
- onChanged: (index)=>_radioOnchanged(index),
- ),
- Text("Jus Kulit Durian"),
- Radio(
- value : 1,
- groupValue: _radioGroupValue,
- onChanged: (index)=>_radioOnchanged(index),
- ),
- Text("Es Kelapa Bakar"),
- Radio(
- value : 2,
- groupValue: _radioGroupValue,
- onChanged: (index)=>_radioOnchanged(index),
- ),
- Text("Susu Kukus"),
- ]),
- ),
- ),
- );
- }
- void _radioOnchanged(index){
- setState(() {
- _radioGroupValue = index;
- _selectedFavorite = _favoriteList[index];
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement