manofi21
8/31/2019 - 8:40 AM

how to show radio in dart

how to show radio in dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _radioVal = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Container(
        padding: EdgeInsets.only(top: 25),
        child:Row(
      children: [0, 1, 2, 3]
          .map((int index) => Radio<int>(
                value: index,
                groupValue: this._radioVal,
                onChanged: (int value) {
                  setState(() => this._radioVal = value);
                },
              ))
          .toList(),
    )
      )));
  }
}