Flutter 单选框 Radio

Posted 安果移不动

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter 单选框 Radio相关的知识,希望对你有一定的参考价值。

代码

import 'package:flutter/material.dart';

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

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

class _PublishPageState extends State<PublishPage> {
  int _part = 1;
  int _partGroupValue = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("发布需求"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            //我是 甲方 乙方
            SizedBox(
              height: 10,
            ),
            Row(
              children: [
                SizedBox(
                  width: 10,
                ),
                Text("我是:"),
                Radio(
                    value: 1,
                    groupValue: _part,
                    onChanged: (value) {
                      debugPrint(value.toString());
                      setState(() {
                        this._part = 1;
                      });
                    }),
                Text("甲方"),
                Radio(
                    value: 2,
                    groupValue: _part,
                    onChanged: (value) {
                      debugPrint(value.toString());
                      setState(() {
                        this._part = 2;
                      });
                    }),
                Text("乙方"),
              ],
            )
          ],
        ),
      ),
    );
  }
}

 

以上是关于Flutter 单选框 Radio的主要内容,如果未能解决你的问题,请参考以下文章

flutter Radio单选框

Flutter学习日记之表单组件Radio单选框&Checkbox复选框的使用

Flutter 专题109 图解自定义 ACERadio 单选框 #yyds干货盘点#

PHP中怎样获取radio单选框的值

angularJs里单选框radio怎么使用ng-model

checbox复选框实现radio单选框的单选功能