Advertisement
BlackBoY_

Favorite_page.dart

Jun 19th, 2022 (edited)
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.84 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class minumanFav extends StatefulWidget {
  4.   int radioGroupValue = 0;
  5.   @override
  6.   State<minumanFav> createState() => _minumanFavState();
  7. }
  8.  
  9. class _minumanFavState extends State<minumanFav> {
  10.   int _radioGroupValue = 0;
  11.   String _selectedFavorite = "";
  12.   List<String> _favoriteList = [];
  13.   @override
  14.  
  15.   void initState(){
  16.     super.initState();
  17.     _favoriteList..add('Jus Kulit Durian')..add('Es Kelapa Bakar')..add('Susu Kukus');
  18.     _radioGroupValue = widget.radioGroupValue;
  19.     _selectedFavorite = _favoriteList[widget.radioGroupValue];
  20.   }
  21.  
  22.   Widget build(BuildContext context) {
  23.     return Scaffold(
  24.       appBar: AppBar(
  25.         title: Text("Minuman Favorite"),
  26.         actions: [
  27.           IconButton(
  28.             icon: Icon(Icons.check),
  29.             onPressed: (){
  30.               Navigator.pop(context, _selectedFavorite);
  31.             },
  32.           )
  33.         ],
  34.       ),
  35.       body: SafeArea(
  36.         child: Padding(
  37.           padding: const EdgeInsets.all(16),
  38.           child: Column(children: [
  39.             Radio(
  40.               value : 0,
  41.               groupValue: _radioGroupValue,
  42.               onChanged: (index)=>_radioOnchanged(index),
  43.             ),
  44.             Text("Jus Kulit Durian"),
  45.             Radio(
  46.               value : 1,
  47.               groupValue: _radioGroupValue,
  48.               onChanged: (index)=>_radioOnchanged(index),
  49.             ),
  50.             Text("Es Kelapa Bakar"),
  51.             Radio(
  52.               value : 2,
  53.               groupValue: _radioGroupValue,
  54.               onChanged: (index)=>_radioOnchanged(index),
  55.             ),
  56.             Text("Susu Kukus"),
  57.           ]),
  58.         ),
  59.       ),
  60.     );
  61.   }
  62.  
  63.   void _radioOnchanged(index){
  64.     setState(() {
  65.       _radioGroupValue = index;
  66.       _selectedFavorite = _favoriteList[index];
  67.  });
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement