English 中文(简体)
骨质分类后自动处理
原标题:Keyboard Dismisses Automatically After Typing or Removing One Character

我在我的“彩虹”中遇到一个问题,即钥匙板在案文栏目中打字或删除一个特性后自动开除。 我有一份清单,列出含有文稿田的、可允许的植被。 然而,每当我打字或删除文本表格中的一种特性时,关键板就突然放弃。

我的法典:

import  package:flutter/material.dart ;
import  package:r6stats/scanner_result.dart ;

class PlayerEditor extends StatefulWidget {
  const PlayerEditor({super.key, required this.playerNames});

  final List<String> playerNames;

  @override
  State<PlayerEditor> createState() => _PlayerEditorState();
}

class _PlayerEditorState extends State<PlayerEditor> {

  @override
  Widget build(BuildContext context) {
    List<String> players = widget.playerNames;

    return Scaffold(
      appBar: AppBar(
        title: const Text("Edit Players"),
        actions: [
          IconButton(
              onPressed: () {
                Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (context) => ScannerResult(playerNames: players),
                  ),
                );
              },
              icon: const Icon(Icons.check))
        ],
      ),
      body: ListView.builder(
        itemCount: players.length,
        itemBuilder: (context, index) => Padding(
          padding: const EdgeInsets.all(8),
          child: Dismissible(
            key: UniqueKey(),
            direction: DismissDirection.startToEnd,
            onDismissed: (direction) {
              final playerName = players[index];
              ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                content: Text("${players[index]} dismissed"),
                action: SnackBarAction(
                  label:  UNDO ,
                  onPressed: () {
                    setState(() {
                      players.insert(index, playerName);
                    });
                  },
                ),
              ));
              setState(() {
                players.removeAt(index);
              });
            },
            background: Container(
              color: Colors.red,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.only(left: 20.0),
              child: const Icon(Icons.delete, color: Colors.white),
            ),
            child: ListTile(
              tileColor: const Color.fromRGBO(194, 194, 194, 100),
              shape: const RoundedRectangleBorder(
                  side: BorderSide(color: Colors.black, width: 1)),
              title: TextFormField(
                initialValue: players[index],
                onChanged: (newValue) {
                  setState(() {
                    players[index] = newValue;
                  });
                },
                style: Theme.of(context)
                    .textTheme
                    .titleMedium!
                    .copyWith(color: Colors.black),
                decoration: const InputDecoration(
                  border: InputBorder.none,
                  focusedBorder: InputBorder.none,
                  hintText:  Enter player name ,
                ),
              ),
              titleTextStyle: Theme.of(context)
                  .textTheme
                  .titleMedium!
                  .copyWith(color: Colors.black),
            ),
          ),
        ),
      ),
    );
  }
}

I ve Trial using GlobalKey for the ListView. 每一可忽略的植被的建筑群和独木块,但问题依然存在。 我如何防止主板在打字或去除特性后自动开除?

任何见解或建议都将受到高度赞赏。 谢谢!

问题回答

我认为,你的法典可能有两个问题。

  1. Since you are changing the list of players, and you can not change the value of widget.playerNames, you must copy the List items. So, do this:
List<String> players = [...widget.playerNames];
  1. You don t need to use setState in your onChanged method.




相关问题
Android: SQLite and ListViews

Firstly, I have found many examples of how to grab data from a db and place it into a list, however this seems to be all for ListActivites. My list is part of the UI and therefore I can t use a ...

WPF synchronize Listview with some ViewCollection

I have a WPF ListView databound to an ObeservableCollection named FilteredAppendixes. Now I create a view with: CollectionViewSource.GetDefaultView(FilteredAppendixes); The CurrentItem property of ...

How to dynamically update a ListView on Android [closed]

On Android, how can I a ListView that filters based on user input, where the items shown are updated dynamically based on the TextView value? I m looking for something like this: -------------------...

How can I load a folders files into a ListView?

I d like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView. My intention is to make a little playlist of sorts so I have to modify a couple of ...

ListView Click event

I have a List of Items which I retrieved from my Sqlite DB... I want to set a Click event for each item. How I can customize this event based on the Item clicked???? Be descriptive... I am a beginner. ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

WPF ListView - is it better in Visual Studio 2010?

I ve tried implementing a readonly grid of items using the WPF ListView. It appears to me that this is a poorly designed and implemented control. (Unlike most of WPF which I like). Specific issues I ...

热门标签