问题:
在点击后退按钮(默认为AppBar小部件)时,有时它不起作用,屏幕会冻结。此后我必须重新启动应用程序。我还尝试用自定义图标替换后退按钮,并给它navigator.pop(context)。但仍然显示相同的错误。
注:我没有使用Cupertino小部件。所有软件均已更新。
我的代码:
在点击后退按钮(默认为AppBar小部件)时,有时它不起作用,屏幕会冻结。此后我必须重新启动应用程序。我还尝试用自定义图标替换后退按钮,并给它navigator.pop(context)。但仍然显示相同的错误。
注:我没有使用Cupertino小部件。所有软件均已更新。
我的代码:
import 'package:flutter/material.dart';
class SearchLocation extends StatefulWidget {
static const String id = 'SearchLocation';
@override
_SearchLocationState createState() => _SearchLocationState();
}
class _SearchLocationState extends State<SearchLocation> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).cardColor,
appBar: AppBar(
backgroundColor: Theme.of(context).accentColor,
title: Text(
'Search Location',
style: Theme.of(context).textTheme.headline1,
),
leading: IconButton(
onPressed: () => Navigator.pop(context),
icon: Icon(
Icons.close,
color: Colors.black,
),
),
),
body: Container(
padding: EdgeInsets.all(8),
child: Column(
children: [
],
),
),
);
}
}
Error:<br>
======== Exception caught by gesture ===============================================================
The following RangeError was thrown while handling a gesture:
RangeError (index): Invalid value: Not in inclusive range 0..1: -1
When the exception was thrown, this was the stack:
#0 List.[] (dart:core-patch/growable_array.dart:177:60)
#1 NavigatorState.didStartUserGesture (package:flutter/src/widgets/navigator.dart:3987:44)
#2 new _CupertinoBackGestureController (package:flutter/src/cupertino/route.dart:737:15)
#3 CupertinoRouteTransitionMixin._startPopGesture (package:flutter/src/cupertino/route.dart:256:12)
#4 CupertinoRouteTransitionMixin.buildPageTransitions.<anonymous closure> (package:flutter/src/cupertino/route.dart:303:36)
...
Handler: "onStart"
Recognizer: HorizontalDragGestureRecognizer#b4e39
debugOwner: _CupertinoBackGestureDetectorState<dynamic>#2f05b
start behavior: start
====================================================================================================
======== Exception caught by gesture ===============================================================
The following StateError was thrown while handling a gesture:
Bad state: No element
When the exception was thrown, this was the stack:
#0 ListMixin.lastWhere (dart:collection/list.dart:180:5)
#1 NavigatorState.pop (package:flutter/src/widgets/navigator.dart:3820:40)
#2 Navigator.pop (package:flutter/src/widgets/navigator.dart:2068:27)
#3 _SearchLocationState.build.<anonymous closure> (package:fb_client/screens/search_location.dart:23:38)
#4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#48bf1
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(24.3, 79.3)
finalLocalPosition: Offset(24.3, 32.3)
button: 1
sent tap down
====================================================================================================
======== Exception caught by gesture ===============================================================
'package:flutter/src/cupertino/route.dart': Failed assertion: line 654 pos 12: '_backGestureController != null': is not true.
====================================================================================================
======== Exception caught by gesture ===============================================================
'package:flutter/src/cupertino/route.dart': Failed assertion: line 660 pos 12: '_backGestureController != null': is not true.
====================================================================================================