我在我的“彩虹”中遇到一个问题,即钥匙板在案文栏目中打字或删除一个特性后自动开除。 我有一份清单,列出含有文稿田的、可允许的植被。 然而,每当我打字或删除文本表格中的一种特性时,关键板就突然放弃。
我的法典:
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. 每一可忽略的植被的建筑群和独木块,但问题依然存在。 我如何防止主板在打字或去除特性后自动开除?
任何见解或建议都将受到高度赞赏。 谢谢!