【问题标题】:PersistedOffset: is in an unexpected statePersistedOffset:处于意外状态
【发布时间】:2022-09-29 04:24:25
【问题描述】:

我试图从一个页面到另一个页面,为此我使用arrow_back icons返回到过去的页面,我使用Navigator.pop(context),但给出了错误PersistedOffset: is in an unexpected state. Flutter Channel:Dev和Device :Web Chrome。谢谢!

class IndividualDetails extends StatefulWidget {
  const IndividualDetails({super.key, required this.chatModel});
  final ChatModel chatModel;
  @override
  State<IndividualDetails> createState() => _IndividualDetailsState();
}
class _IndividualDetailsState extends State<IndividualDetails> {
  @override
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leadingWidth: 70,
        leading: InkWell(
          onTap: () {
             Navigator.of(context).pop();
          },
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const [
              Icon(
                Icons.arrow_back,
                size: 24,
              ),
              CircleAvatar(
                radius: 20,
                backgroundColor: Colors.blueGrey,
              child: SvgPicture.asset(
                widget.chatModel.isGroup ? \'assets/groups.svg\' : \'assets/person.svg\',
                color: Colors.white,
                height: 32,
                width: 32,
              ),
              ),
            ],
          ),
        ),
      ),
    );
  }
 }

这是卡片,当我点击这张卡片时,它会跳转到IndividualDetails() 页面。当我单击返回按钮时,我想返回到这张卡。

class CustomCard extends StatelessWidget {
  const CustomCard({super.key, required this.chatModel});
  final ChatModel chatModel;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => IndividualDetails(
                chatModel: chatModel,
              ))),
      child: Column(
        children: [
          ListTile(
            leading: CircleAvatar(
              radius: 30,
              backgroundColor: Colors.blueGrey,
              child: SvgPicture.asset(
                chatModel.isGroup ? \'assets/groups.svg\' : \'assets/person.svg\',
                color: Colors.white,
                height: 32,
                width: 32,
              ),
            ),
            trailing: Text(chatModel.time),
            title: Text(
              chatModel.name,
              style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
            ),
            subtitle: Row(
              children: [
                const Icon(
                  Icons.done_all,
                  color: Colors.blue,
                  size: 20,
                ),
                const SizedBox(
                  width: 2.0,
                ),
                Text(chatModel.currentMessage),
              ],
            ),
          ),
          const Padding(
            padding: EdgeInsets.only(left: 80.0, right: 20.0),
            child: Divider(
              thickness: 1.5,
            ),
          ),
        ],
      ),
    );
  }
}

标签: flutter


【解决方案1】:

使用 Navigator.pop(context) 时我遇到了同样的问题。这只发生在设备:Web Chrome 上。

此行为不会发生在 Android 或 iPhone 设备中。

我对此的临时解决方案: Navigator.pushNamed(context, parent.routeName) 或 Navigator.pushNamedAndRemoveUntil(context, parent.routeName, (r) => false) 视情况而定。

祝你好运。

【讨论】:

    猜你喜欢
    • 2019-09-28
    • 2019-10-02
    • 2016-11-13
    • 2016-02-28
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多