Search code examples
flutterdartdismissible

Flutter Dismissible not working anymore, but code looks correct


I've been writing an application which requires the users to be able to dismiss objects from a list. I had this all working, and then it suddenly stopped working, and I have no idea why.

I've commented out almost all of the code - this is all that remains, but the dismissible STILL doesn't work (although it worked fine previously!!!!):

//... 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,
      ),
    );

//....

The swipe action just refuses to work AT ALL, and I'm tearing my hair out as to why. Any Flutter experts out there able to help me out?

Thanks!


Solution

  • It seems the error came from running a timer at every 44 millisecond intervals and setting a boolean in there.

    Not sure why that was, as the boolean in question was unrelated to the dismissible.

    Thanks for your help, folks.