Flutter Tutorials

Flutter app development tutorials


flutter – Radio button size

main.dart


import 'package:flutter/material.dart';

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

class FlutterExample extends StatelessWidget {
  const FlutterExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Example',
        theme: ThemeData(primarySwatch: Colors.red),
        home: const StateExample()
    );
  }
}

class StateExample extends StatefulWidget {
  const StateExample({Key? key}) : super(key: key);

  @override
  _StateExampleState createState() => _StateExampleState();
}


enum colors { red, green, blue }

class _StateExampleState extends State<StateExample> {
  colors _color = colors.green;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color(0xFFF5F5F5),
        appBar: AppBar(
            title: const Text("Flutter - Radio Button Size")
        ),
        body: bodyContent()
    );
  }


  bodyContent() {
    return Column(
      children: [
        ListTile(
          title: const Text("Red"),
          tileColor: Colors.blue[100],
          contentPadding: const EdgeInsets.symmetric(
              horizontal: 15, vertical: 5
          ),
          leading: Transform.scale(
              scale: 2,
              child: Radio<colors>(
                value: colors.red,
                groupValue: _color,
                onChanged: (colors? value){
                  setState(() {
                    _color = value??_color;
                  });
                },)
          ),
        ),
        ListTile(
            title: const Text("Green"),
            tileColor: Colors.blue[100],
            contentPadding: const EdgeInsets.symmetric(
                horizontal: 15, vertical: 5
            ),
            leading: Transform.scale(
              scale: 2,
              child: Radio<colors>(
                value: colors.green,
                groupValue: _color,
                onChanged: (colors? value){
                  setState(() {
                    _color = value??_color;
                  });
                },
              ),)
        ),
        ListTile(
            title: const Text("Blue"),
            tileColor: Colors.blue[100],
            contentPadding: const EdgeInsets.symmetric(
                horizontal: 15, vertical: 5
            ),
            leading: Transform.scale(
              scale: 2,
              child: Radio<colors>(
                value: colors.blue,
                groupValue: _color,
                onChanged: (colors? value){
                  setState(() {
                    _color = value??_color;
                  });
                },
              ),)
        )
      ],
    );
  }
}

More flutter tutorials



About Me

Flutter Developer

Design a site like this with WordPress.com
Get started