我似乎找不到合适的术语来搜索我的问题。我现在有一个应用程序几乎完成了一个问题。首先,我想先解释一下这个应用程序。该应用程序是一个 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
(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)
下面是我的代码:
main.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:usesCleartextTraffic
。 here您可以找到解决方案。
关于android - 如何在检测到登录时更新所有 WebView 选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59296903/