Hello everyone i am a beginner in Flutter Development, i want to switch pages using the arrow back icon on the ListCompetitionScreen to go to the homeScreen ( this is my default start screen ), but when I opened the application and move to ListCompetitionScreen and then I clicked on the arrow back icon from the ListCompetitionScreen to go to the homeScreen there was an error like this:
════════ Exception caught by gesture ═══════════════════════════════════════════
The following assertion was thrown while handling a gesture:
A page-based route cannot be completed using imperative api, provide a new list without the corresponding Page to Navigator.pages instead.
'package:flutter/src/widgets/navigator.dart':
package:flutter/…/widgets/navigator.dart:1
Failed assertion: line 3139 pos 7: '!pageBased || isWaitingForExitingDecision'
2
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.yml
#8 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:315
#9 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:652
#10 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:309
#11 BaseTapGestureRecognizer.handlePrimaryPointer
package:flutter/…/gestures/tap.dart:242
#12 PrimaryPointerGestureRecognizer.handleEvent
package:flutter/…/gestures/recognizer.dart:670
#13 PointerRouter._dispatch
package:flutter/…/gestures/pointer_router.dart:98
#14 PointerRouter._dispatchEventToRoutes.<anonymous closure>
package:flutter/…/gestures/pointer_router.dart:143
#15 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#16 PointerRouter._dispatchEventToRoutes
package:flutter/…/gestures/pointer_router.dart:141
#17 PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:127
#18 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:495
#19 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:475
#20 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:430
#21 GestureBinding._handlePointerEventImmediately
package:flutter/…/gestures/binding.dart:420
#22 GestureBinding.handlePointerEvent
package:flutter/…/gestures/binding.dart:383
#23 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:330
#24 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:299
#25 _invoke1 (dart:ui/hooks.dart:328:13)
#26 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:429:7)
#27 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
(elided 2 frames from class _AssertionError)
Handler: "onTap"
Recognizer: TapGestureRecognizer#8d8d1
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(41.1, 51.0)
finalLocalPosition: Offset(33.1, 19.0)
button: 1
sent tap down
════════════════════════════════════════════════════════════════════════════════
can anyone help me to find the solution of this problem ?
here is the detail of my code :
//MyApp
class MyApp extends StatefulWidget {
final int initialPageIndex;
const MyApp({super.key, this.initialPageIndex = 0});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late int _pageIndex;
@override
void initState() {
super.initState();
_pageIndex = widget.initialPageIndex;
}
final List<Widget> _pages = [
const HomeScreen(),
const ListCompetitions(),
const ScanQrCode(),
const CalendarCompetition(),
const ProfileUser(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
bottomNavigationBar: _pageIndex == 2
? null
: BottomNavBar(
currentIndex: _pageIndex,
onTap: (index) {
setState(() {
_pageIndex = index;
});
},
),
body: _pages[_pageIndex],
);
}
}
//ListCompetitionsScreen
class ListCompetitions extends StatefulWidget {
const ListCompetitions({super.key});
@override
State<ListCompetitions> createState() => _ListCompetitionsState();
}
class _ListCompetitionsState extends State<ListCompetitions> {
final ScrollController _scrollController = ScrollController();
@override
void initState() {
super.initState();
// Add scroll listener
_scrollController.addListener(_scrollListener);
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
void _scrollListener() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
Provider.of<GetCompetitionController>(context, listen: false).loadMore();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: const Icon(
Icons.arrow_back,
color: Colors.black,
),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const MyApp(initialPageIndex: 0),
),
);
},
),
title: Text(
'List Competitions',
style: GoogleFonts.poppins(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
centerTitle: true,
),
.....
the rest of my code