android - 如何在检测到登录时更新所有 WebView 选项卡?

标签 android flutter flutter-layout flutter-dependencies

我似乎找不到合适的术语来搜索我的问题。我现在有一个应用程序几乎完成了一个问题。首先,我想先解释一下这个应用程序。该应用程序是一个 webview 应用程序,底部导航栏上有 5 个选项卡。我正在使用官方 Flutter 开发团队 webview_flutter

顺便说一句,我有 2 个问题,它们在 block 引用中

现在剩下的问题是,当我登录到我在使用 webview 的选项卡之一中设置的 url 时,它会生成

(1) an error (image below, for some reason the error wont appear again on my emulator (it happened on the first time) BUT on my phone it appears) in the tab I used to login and not redirects automatically to the URL ive set

Error produced

(2) and not all tabs refreshes automatically to detect the login event (I need to navigate in the url of the website and go back to detect the login event (which is what I dont want to happen)

下面是我的代码:

ma​​in.dart

import 'package:syncshop_webview/widgets/cart_page.dart';
import 'package:syncshop_webview/widgets/categories_page.dart';
import 'package:syncshop_webview/widgets/home_page.dart';
import 'package:syncshop_webview/widgets/profile_account.dart';
import 'package:syncshop_webview/widgets/search_page.dart';

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

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MyAppState();
  }
}

class MyAppState extends State<MyApp> {
int _selectedPage = 2;
final _pageOptions = [
  CategoriesPage(),
  SearchPage(),
  HomePage(),
  CartPage(),
  ProfileAccount(),
];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Sync Shop',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
      body: IndexedStack(
        index: _selectedPage,
        children: _pageOptions,
      ),
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _selectedPage,
          onTap: (int index) {
            setState((){
      _selectedPage = index;
            });
          },
          items: [
          BottomNavigationBarItem(icon: Icon(Icons.category), title: Text("Categories"),
          ),
          BottomNavigationBarItem(icon: Icon(Icons.search), title: Text("Search"),
          ),
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home"),
          ),
          BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), title: Text("Cart"),
          ),
          BottomNavigationBarItem(icon: Icon(Icons.account_circle), title: Text("Profile"),
          ),
          ],
          ),
      ),
      );
  }
}

我的一个标签,特别是用户应该登录的地方

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

class ProfileAccount extends StatefulWidget {

  @override
  _ProfileAccountState createState() => _ProfileAccountState();
}

class _ProfileAccountState extends State<ProfileAccount> with AutomaticKeepAliveClientMixin<ProfileAccount>{

WebViewController _myController;
  Widget build(BuildContext context) {
    super.build(context);
    return SafeArea(
          child: Scaffold(
            body: WebView(
            initialUrl: 'https://syncshop.online/en/login',
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (controller) {
              _myController = controller;
            },
          onPageFinished: (initialUrl) {
              _myController.evaluateJavascript("document.getElementsByClassName('footer-container')[0].style.display='none';");
          },
        ),
      ),
    );
  }
  @override
  bool get wantKeepAlive => true;
}

最佳答案

这是 API 级别 28 或更高级别中的问题。出于安全目的,他们禁用了 android:usesCleartextTraffichere您可以找到解决方案。

关于android - 如何在检测到登录时更新所有 WebView 选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59296903/

相关文章:

android - 在 Android 中使用 ViewPager 和 fragment 的 EditText 出现 NullPointerException

flutter - 如何将参数传递给 Mobx Controller (Flutter)

flutter - 如何在没有等待的情况下获得 future 值(value)?

firebase - 即使我修改了某些字段,如何才能每次只从 Firestore 获取一次数据?

flutter - 如何垂直或水平居中堆栈中的小部件?

java - 分数变量不会更新,并且必须是最终的?

java - Android Studio 更新位置时位置标记消失

flutter - flutter 中的卡片 View 和布局

android - 处理Listview问题每一行中的按钮事件

flutter - 如果文本溢出抖动,如何自动换行