小编Ale*_*ana的帖子

Flutter DataTable 选择行

我在颤振中遇到 DataTable 问题。我想更改行的状态,当用户单击其中一个时,但我发现如何在 DataRow 中使用 selected: true 来“手动”执行此操作。

如何通过更改状态让用户只选择一行,然后取消选择其余行?

content: Column(
               children: <Widget>[
                 DataTable(
                   columns: [
                     DataColumn(label: Text('Language')),
                     DataColumn(label: Text('Translation')),
                   ],
                   rows: [
                     DataRow(selected: true, cells: [
                       DataCell(
                         Text(
                           "RO",
                           textAlign: TextAlign.left,
                           style: TextStyle(fontWeight: FontWeight.bold),
                         ),
                         onTap: () {
                           setState(() {
                             color = Colors.lightBlueAccent;

                           });
                         },
                       ),
                       DataCell(
                         TextField(
                           decoration: InputDecoration(
                               border: InputBorder.none, hintText: 'paine'),
                         ),
                       ),
                     ]),
                     DataRow(cells: [
                       DataCell(
                           Text(
                             "EN",
                             textAlign: TextAlign.left,
                             style: TextStyle(fontWeight: FontWeight.bold),
                           ), onTap: () {
                         print('EN is clicked');
                       }),
                       DataCell(
                         TextField(
                           decoration: InputDecoration( …
Run Code Online (Sandbox Code Playgroud)

mobile row datarow dart flutter

2
推荐指数
1
解决办法
3899
查看次数

Flutter 弹出对话框不会在 setState() 上更新

我有一个颤振问题,当用户按下特定按钮时,我创建了一个弹出对话框,他可以在其中选中复选框。

问题是 setState() 上的复选框没有更新,就在我关闭弹出对话框并再次打开它之后,我可以看到我选中了它们。

我在弹出对话框中设置 setState() 不好吗?我似乎没看出问题出在哪里。

这是代码:

编辑:更新的代码:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class AlwaysDisabledFocusNode extends FocusNode {
  @override
  bool get hasFocus => false;
}

class MultiLanguagePopupProduct extends StatefulWidget {
  @override
  _MultiLanguagePopupProductState createState() =>
      _MultiLanguagePopupProductState();
}

class _MultiLanguagePopupProductState extends State<MultiLanguagePopupProduct> {
  int selectedIndex = -1;

  String text = '';

  @override
  Widget build(BuildContext context) {
    return StatefulBuilder(
        builder: (context, setState) {
          return Container(
            child: TextField(
              focusNode: AlwaysDisabledFocusNode(),
              enableInteractiveSelection: false,
              decoration: InputDecoration(
                suffixIcon: IconButton(
                  icon: Icon(FontAwesomeIcons.boxOpen),
                ),
                labelText: 'Name and …
Run Code Online (Sandbox Code Playgroud)

mobile dart flutter

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

标签 统计

dart ×2

flutter ×2

mobile ×2

datarow ×1

row ×1