Flutter Dismissible 不再工作,但代码看起来正确
Flutter Dismissible not working anymore, but code looks correct
我一直在编写一个应用程序,它要求用户能够从列表中删除对象。我本来一切正常,然后它突然停止工作,我不知道为什么。
我已经注释掉了几乎所有的代码——剩下的就是这些了,但是可忽略的 STILL 仍然不起作用(尽管它之前工作得很好!!!!):
//... setup stuff not relevant to question
class _Screen extends State<Screen> {
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: profileCard(true),
);
Dismissible profileCard(bool centre) {
return Dismissible(
key: GlobalKey(),
background: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.green,
),
secondaryBackground: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.red,
),
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.purple,
),
);
//....
滑动操作根本无法正常工作根本,我很想知道为什么。有 Flutter 专家可以帮助我吗?
谢谢!
如@Benedikt J Schlegel 所述,您的代码适用于 Dismissible
。
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Screen(),
));
}
class Screen extends StatefulWidget {
@override
_ScreenState createState() => _ScreenState();
}
class _ScreenState extends State<Screen> {
Dismissible profileCard(bool centre) {
return Dismissible(
key: GlobalKey(),
background: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.green,
),
secondaryBackground: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.red,
),
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.purple,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Dismissible'),
),
body: profileCard(true));
}
}
错误似乎来自 运行 每 44 毫秒间隔一次的计时器并在其中设置了一个布尔值。
不确定为什么会这样,因为所讨论的布尔值与可忽略项无关。
谢谢大家的帮助。
我一直在编写一个应用程序,它要求用户能够从列表中删除对象。我本来一切正常,然后它突然停止工作,我不知道为什么。
我已经注释掉了几乎所有的代码——剩下的就是这些了,但是可忽略的 STILL 仍然不起作用(尽管它之前工作得很好!!!!):
//... setup stuff not relevant to question
class _Screen extends State<Screen> {
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: profileCard(true),
);
Dismissible profileCard(bool centre) {
return Dismissible(
key: GlobalKey(),
background: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.green,
),
secondaryBackground: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.red,
),
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.purple,
),
);
//....
滑动操作根本无法正常工作根本,我很想知道为什么。有 Flutter 专家可以帮助我吗?
谢谢!
如@Benedikt J Schlegel 所述,您的代码适用于 Dismissible
。
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Screen(),
));
}
class Screen extends StatefulWidget {
@override
_ScreenState createState() => _ScreenState();
}
class _ScreenState extends State<Screen> {
Dismissible profileCard(bool centre) {
return Dismissible(
key: GlobalKey(),
background: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.green,
),
secondaryBackground: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.red,
),
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.3,
color: Colors.purple,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Dismissible'),
),
body: profileCard(true));
}
}
错误似乎来自 运行 每 44 毫秒间隔一次的计时器并在其中设置了一个布尔值。
不确定为什么会这样,因为所讨论的布尔值与可忽略项无关。
谢谢大家的帮助。