【问题标题】:how to create radio button inside the dropdown menu in flutter?如何在颤动的下拉菜单中创建单选按钮?
【发布时间】:2021-11-04 23:55:14
【问题描述】:

【问题讨论】:

  • 这可能对你有帮助.. stackoverflow.com/questions/44085543/…
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: android ios flutter


【解决方案1】:

为此,您必须使用 RadioListTile。这段代码来自flutterdocumentation,你可以试试:

import 'package:flutter/material.dart';

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

/// This is the main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyStatefulWidget(),
      ),
    );
  }
}

enum SingingCharacter { lafayette, jefferson }

/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  SingingCharacter? _character = SingingCharacter.lafayette;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        RadioListTile<SingingCharacter>(
          title: const Text('Lafayette'),
          value: SingingCharacter.lafayette,
          groupValue: _character,
          onChanged: (SingingCharacter? value) {
            setState(() {
              _character = value;
            });
          },
        ),
        RadioListTile<SingingCharacter>(
          title: const Text('Thomas Jefferson'),
          value: SingingCharacter.jefferson,
          groupValue: _character,
          onChanged: (SingingCharacter? value) {
            setState(() {
              _character = value;
            });
          },
        ),
      ],
    );
  }
}

【讨论】:

  • 如果您得到答案,请接受关闭此问题主题的答案。
  • 不,因为我需要在 DropDownButton 中的 RadioListTile 内。有可能吗?
  • 您可以在返回下拉菜单中将其与下拉按钮混合使用。
  • 嘿哥们,我还有个疑问!
猜你喜欢
  • 2019-07-04
  • 1970-01-01
  • 2021-09-17
  • 2010-09-19
  • 1970-01-01
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多