Skip to content

Android app with CupertinoPageTransitionsBuilder() and MaterialPageRoute() can't use gesture way to back previous page with no error threw and stucked #124850

@Cierra-Runis

Description

@Cierra-Runis

Is there an existing issue for this?

Steps to reproduce

  1. Set theme of MaterialApp as below:
@override
  Widget build(BuildContext context) {
    ThemeData theme = ThemeData(
      useMaterial3: true,
      pageTransitionsTheme: const PageTransitionsTheme(builders: {
        TargetPlatform.android: CupertinoPageTransitionsBuilder(),
      }),
    );

    return MaterialApp(
      theme: theme,
      home: const MercuriusSplashPage(),
    );
  }
  1. Use MaterialPageRoute to change page:
  Navigator.push(
    context,
    MaterialPageRoute(
      builder: (context) => const MercuriusProfilePage(),
    ),
  );
  1. At android device with 3-button nagivation bar, while using gesture way to back previous page, app stucks with no error threw and can't revice any more click event, you can only back previous page with back button in 3-button nagivation bar.

Expected results

It's confused that it doesn't throw a error to figure out what happened. So I expect Flutter throw a error or makes using gesture way to back previous page work at step1~2 situation.

Actual results

  1. At frist I change platform of theme as below, then the issues in step 3 disappered.
  ThemeData theme = ThemeData(
    useMaterial3: true,
    platform: TargetPlatform.iOS,
    pageTransitionsTheme: const PageTransitionsTheme(builders: {
      TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
    }),
  );

but it's not a good way abviousily.

  1. Here's my resolution now:
  • don't set platform and pageTransitionsTheme in theme
  ThemeData theme = ThemeData(
    useMaterial3: true,
  );
  • change all MaterialPageRoute to CupertinoPageRoute
  Navigator.push(
    context,
    CupertinoPageRoute(
      builder: (context) => const MercuriusProfilePage(),
    ),
  );
  1. Perfect!

Code sample

Code sample(I write it in dartpad have no test in real device)
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        pageTransitionsTheme: const PageTransitionsTheme(builders: {
          TargetPlatform.android: CupertinoPageTransitionsBuilder(),
        }),
      ),
      home: const MyHomePage1(),
    );
  }
}

class MyHomePage1 extends StatelessWidget {

  const MyHomePage1({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('page1'),
      ),
      body: Center(
        child: TextButton(
          child: const Text('to page2'),
          onPressed:(){
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => const MyHomePage2(),
              ),
            );
          }
        )
      ),
    );
  }
}

class MyHomePage2 extends StatelessWidget {

  const MyHomePage2({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('page2'),
      ),
      body: const Center(
        child: Text('page2')
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.7.10, on Active code page: 65001

Microsoft Windows [版本 10.0.22621.1265], locale zh-CN)
    • Flutter version 3.7.10 on channel stable at D:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4b12645012 (10 days ago), 2023-04-03 17:46:48 -0700
    • Engine revision ec975089ac
    • Dart version 2.19.6
    • DevTools version 2.20.1

[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\28642\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33205.214
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.77.3)
    • VS Code at C:\Users\28642\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.62.0

[√] Connected device (4 available)
    • V2055A (mobile)   • 30546631470061P • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows         • windows-x64    • Active code page: 65001

      Microsoft Windows [版本 10.0.22621.1265]
    • Chrome (web)      • chrome          • web-javascript • Google Chrome 111.0.5563.148
    • Edge (web)        • edge            • web-javascript • Microsoft Edge 112.0.1722.39

HTTP Host availability check is taking a long time...[!] HTTP Host Availability
    X HTTP host "https://maven.google.com/" is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到

    X HTTP host "https://cloud.google.com/" is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到


! Doctor found issues in 2 categories.

Metadata

Metadata

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.f: routesNavigator, Router, and related APIs.found in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions