1

This is the problem that I got => The following assertion was thrown building CupertinoNavigationBarBackButton(dirty, dependencies: [_ModalScopeStatus]): CupertinoNavigationBarBackButton should only be used in routes that can be popped 'package:flutter/src/cupertino/nav_bar.dart': Failed assertion: line 1333 pos 9: 'currentRoute?.canPop == true'

I really do not understand this situation because I used previous 2 pages there is no problem but last page made problem.

Here is my related code part:(third page)

 @override
  Widget build(BuildContext context) {
    final name = basename(widget.file!.path);
    if(Platform.isIOS){
      return CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          leading: CupertinoNavigationBarBackButton(
            color: CupertinoColors.white,
          ),

This is he way how to come here: (first page)

CupertinoButton(
   padding: EdgeInsets.all(0),
   child: Icon(CupertinoIcons.list_bullet, color: CupertinoColors.white,),
   onPressed: () => {
      Navigator.push(context, CupertinoPageRoute(builder: (context) => ConsumptionReportsScreen(location: widget.location)))
   }
),

(second page)

onTap: () async {
   // final file = await PDFApi.loadNetwork(reports[index].pdfUrl);
   const url = 'https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf';
   final file = await PDFApi().loadNetwork(url);
   Navigator.push(context, CupertinoPageRoute(builder: (context) => PdfViewerScreen(file: file)));
  },
theredboy
  • 92
  • 10

3 Answers3

0

The error you're getting shows that the page you're currently on can't be popped.

Failed assertion: line 1333 pos 9: 'currentRoute?.canPop == true'

Are you sure there are pages in the stack that can be popped to?

Advait
  • 574
  • 3
  • 12
  • It is opening, I cannot show you right now but i can navigate. There is only problem that back button place in navigation bar turns red screen first then it is closing. Although it is closing, firstly red screen is a problem. I do not know how to fix it – theredboy Mar 30 '22 at 08:48
  • Can you add the code for how you come to this page, it'll be somewhat like `Navigator.push` or something, and also add the code for how you're popping these pages. – Advait Mar 30 '22 at 08:51
  • Im going to add right now – theredboy Mar 30 '22 at 08:54
  • I have added the way, you can see from the question @Advait – theredboy Mar 30 '22 at 09:02
0

first return a material app and in and inside it use CupertionoPageScaffold() as home page , i hope this will help

    import 'dart:io';

    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';

    void main() => runApp(MyApp());

    class MyApp extends StatefulWidget {
      const MyApp({Key? key}) : super(key: key);

      @override
       State<MyApp> createState() => _MyAppState();
    }

    class _MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
      if(Platform.isIOS){
       return MaterialApp(
        home: CupertinoPageScaffold(
          child: Container(),
        ),
      );
     }else {
      return MaterialApp(
        home: Scaffold(),
      );
     }
    }
   }
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
0

Try below code, I have try other way

CupertinoPageScaffold(
  navigationBar: CupertinoNavigationBar(
    backgroundColor: CupertinoColors.activeGreen,
    middle: const Text('Sample Code'),
    leading: GestureDetector(
      onTap: () {
        print('Button Pressed');
        Navigator.of(context).pop();
      },
      child: Icon(
        CupertinoIcons.left_chevron,
        color: CupertinoColors.white,
      ),
    ),
  ),
  child: Container(),
),

Result screen-> image

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40