Skip to content

[webview Android] Flicker issue when navigating routes #96177

@EArminjon

Description

@EArminjon

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Select the music icon from the bottom navigation bar.
  3. See the flicker.

Expected results:
We expected a smooth transition between the webview page and the others.

Actual results:
We see a flicker, the webview appear once again when transition is executed.

Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<NavigatorState> globalKey = GlobalKey<NavigatorState>();
  int index = 0;

  Route<dynamic> normal(Widget widget, RouteSettings settings) => MaterialPageRoute<Widget>(
        settings: settings,
        builder: (BuildContext context) => widget,
      );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Test webview")),
      body: Navigator(
        key: globalKey,
        initialRoute: "test1",
        onGenerateRoute: (RouteSettings settings) {
          switch (settings.name) {
            case "test1":
              return normal(const Test1(), settings);
            case "test2":
              return normal(const Test2(), settings);
            case "test3":
              return normal(const Test3(), settings);
          }
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: index,
        onTap: (index) {
          switch (index) {
            case 0:
              globalKey.currentState?.pushNamed("test1");
              break;
            case 1:
              globalKey.currentState?.pushNamed("test2");
              break;
            case 2:
              globalKey.currentState?.pushNamed("test3");
              break;
          }
          setState(() => this.index = index);
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.music_note), label: 'Music'),
          BottomNavigationBarItem(icon: Icon(Icons.notifications), label: 'Notifications'),
        ],
      ),
    );
  }
}

class Test1 extends StatelessWidget {
  const Test1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const WebView(
      initialUrl: 'https://flutter.dev',
      javascriptMode: JavascriptMode.unrestricted,
      backgroundColor: Color(0x00000000),
    );
  }
}

class Test2 extends StatelessWidget {
  const Test2({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
    );
  }
}

class Test3 extends StatelessWidget {
  const Test3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.orange,
    );
  }
}
name: untitled
description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment:
  sdk: ">=2.15.1 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.4

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^1.0.4
  webview_flutter: ^3.0.0

flutter:
  uses-material-design: true
Logs
[√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [version 10.0.19044.1415], locale fr-FR)
    • Flutter version 2.8.1 at C:\Users\********\Documents\Softwares\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at C:\Users\********\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: C:\Users\********\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\203.7935034\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[√] Android Studio
    • Android Studio at C:\Users\********\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\203.7935034
    • Flutter plugin version 63.0.1
    • Dart plugin version 203.8452
    • android-studio-dir = C:\Users\********\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\203.7935034
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] Connected device (4 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)

Screenrecorder-2022-01-05-15-44-32-813.1.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsfound in release: 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions