小编Fel*_*hes的帖子

如何在 Flutter 中设置默认选中的单选按钮?

默认情况下,Flutter 将所有单选按钮显示为空(未选中)。

如何设置默认选中的单选按钮?

我发布这个问题是为了记录我的解决方案,这可能会对某些人有所帮助,并且还开始讨论这个问题,因为我在这里没有找到任何相关信息。

在单选按钮代码下方:

class _ProductTypeScreen extends State<ProductType> {

  String _radioValue; //Initial definition of radio button value
  String choice;

  void radioButtonChanges(String value) {
    setState(() {
      _radioValue = value;
      switch (value) {
        case 'one':
          choice = value;
          break;
        case 'two':
          choice = value;
          break;
        case 'three':
          choice = value;
          break;
        default:
          choice = null;
      }
      debugPrint(choice); //Debug the choice in console
    });
  }

  // Now in the BuildContext... body widget:

  @override
  Widget build(BuildContext context) {
  //First of the three radio …
Run Code Online (Sandbox Code Playgroud)

radio-button flutter flutter-layout

8
推荐指数
2
解决办法
3万
查看次数

如何在flutter中增加文本字段标签大小(宽度)?

有什么方法可以增加flutter中的文本字段标签宽度,以避免出现省略号(...)?

标签始终小于文本字段区域。

我所能想到的改善这一点,就是减少内容填充的“开始”和“结束”,但效果微乎其微。

                  child: TextField(
                    decoration: InputDecoration(
                        labelText: "em Dólares",
                        labelStyle: TextStyle(color: Colors.amber[600],
                            fontStyle: FontStyle.italic),
                        border: OutlineInputBorder(),
                        fillColor: Colors.black12,
                        filled: true,
                        contentPadding: EdgeInsetsDirectional.only(top: 20.0, bottom: 20.0, start: 5.0, end: 5.0),  //<-- weak solution
                        prefixText: "US\$"),
                    style: TextStyle(color: Colors.amber[600], fontSize: 20.0),
                  )
Run Code Online (Sandbox Code Playgroud)

Ps:我在上面的代码中隐藏了文本字段中一些不必要的属性,如控制器、输入格式、键盘类型。

在此处输入图片说明

flutter flutter-layout

6
推荐指数
1
解决办法
7292
查看次数

标签 统计

flutter ×2

flutter-layout ×2

radio-button ×1