Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when dragging the swipe action cell item out of screen #1

Closed
gliese667c opened this issue Jul 23, 2020 · 6 comments
Closed

Crash when dragging the swipe action cell item out of screen #1

gliese667c opened this issue Jul 23, 2020 · 6 comments

Comments

@gliese667c
Copy link

════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building Container(bg: BoxDecoration(color: Color(0xff050505)), margin: EdgeInsets(1.0, 0.0, 1.0, 0.0)):
The getter 'position' was called on null.
Receiver: null
Tried calling: position

The relevant error-causing widget was
    Container 
When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:51:5)
#1      _SwipeActionCellState._addScrollListener 
package:flutter_swipe_action_cell/core/swipe_action_cell.dart:207
#2      _SwipeActionCellState.didChangeDependencies 
package:flutter_swipe_action_cell/core/swipe_action_cell.dart:191
#3      StatefulElement._firstBuild 
package:flutter/…/widgets/framework.dart:4716
#4      ComponentElement.mount 
package:flutter/…/widgets/framework.dart:4531
...
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5028 pos 14: '_dependents.isEmpty': is not true.
The relevant error-causing widget was
    MediaQuery 
lib/main.dart:98
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by scheduler library ═════════════════════════════════
Cannot get size from a render object that has not been through layout.
════════════════════════════════════════════════════════════════════════════════
@luckysmg luckysmg added the bug It is something doesn't working or incorrect label Jul 23, 2020
@luckysmg
Copy link
Owner

luckysmg commented Jul 24, 2020

Can you give me your demo code? I just cant reproduce your problem.. @gliese667c

@luckysmg
Copy link
Owner

I guess that you put cell in a widget that is not scrollable .You should put cells in ListView or CustomScrollView....instead of Column...@gliese667c

@luckysmg luckysmg added waiting response Wait the author of this issue to response and removed bug It is something doesn't working or incorrect labels Jul 24, 2020
@gliese667c
Copy link
Author

No, I put it in ReorderableListView, the long-press cell will crash the app.
Reproduce Code

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swipe_action_cell/core/swipe_action_cell.dart';

void main() async {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Page1(
        title: "haha",
      ),
    );
  }
}

class Page1 extends StatefulWidget {
  Page1({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _Page1State createState() => _Page1State();
}

class _Page1State extends State<Page1> {
  List list;

  @override
  void initState() {
    super.initState();
    list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ReorderableListView(
        onReorder: (_, __) {},
        children: _buildList(),
      ),
    );
  }

  List<Widget> _buildList() {
    return List.generate(list.length, (index) => _item(index));
  }

  Widget _item(int index) {
    return SwipeActionCell(
      ///this key is necessary
      key: ObjectKey(list[index]),

      ///this is the same as iOS native
      performsFirstActionWithFullSwipe: true,
      actions: <SwipeAction>[
        SwipeAction(
            title: "delete",
            onTap: (CompletionHandler handler) async {
              await handler(true);
              list.removeAt(index);
              setState(() {});
            },
            color: Colors.red),
        SwipeAction(
            widthSpace: 120,
            title: "popAlert",
            onTap: (CompletionHandler handler) async {
              ///false means that you just do nothing,it will close
              /// action buttons by default
              handler(false);
              showCupertinoDialog(
                  context: context,
                  builder: (c) {
                    return CupertinoAlertDialog(
                      title: Text('ok'),
                      actions: <Widget>[
                        CupertinoDialogAction(
                          child: Text('confirm'),
                          isDestructiveAction: true,
                          onPressed: () {
                            Navigator.pop(context);
                          },
                        ),
                      ],
                    );
                  });
            },
            color: Colors.orange),
      ],
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text("this is index of ${list[index]}", style: TextStyle(fontSize: 40)),
      ),
    );
  }
}

@luckysmg
Copy link
Owner

Thanks for your response. I will try your code to find problem.

@luckysmg luckysmg removed the waiting response Wait the author of this issue to response label Jul 24, 2020
@luckysmg
Copy link
Owner

I have pushed a new version of this package (1.0.3+1). You can try again.@gliese667c

@luckysmg
Copy link
Owner

I will close this issue . If there are problems remains , you can reopen this issue whenever you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants