4

BottomNavigationBar を使用してページ間を変更する Flutter アプリケーションを作成しています。ページの 1 つに Webview があり (Flutter 開発チームが開発したプラグインを使用しています)、別のタブに移動して戻ってきたときに Webview の状態を維持できません。方法があるかどうかもわかりません。

PageStorageBucket と AutomaticKeepAliveClientMixin を使用してみましたが、役に立ちませんでした。PageStorageBucket を使用すると、単純な ListView の状態がタブ間で保持されることに気付きましたが、Webview では機能しないようです。

最小限の再現可能な例を次に示します。

class _MyHomePageState extends State<MyHomePage> {
  List<Widget> _pages;
  int _selectedIndex = 0;

  @override
  void initState() {
    super.initState();
    _pages = [
      Center(
        child: Text('HOME'),
      ),
      WebView(
        initialUrl: 'https://flutter.io',
        javascriptMode: JavascriptMode.unrestricted,
      )
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
          BottomNavigationBarItem(icon: Icon(Icons.web), title: Text('Web')),
        ],
        currentIndex: _selectedIndex,
        onTap: (index) {
          setState(() {
            _selectedIndex = index;
          });
        },
      ),
      body: _pages[_selectedIndex],
    );
  }

https://imgur.com/qOm7uEa

Webview タブに戻ったときに Web を同じ状態にしたいのですが、リロードしたくありません。

4

2 に答える 2