我正在将本地身份验证添加到颤振的 Web 视图中。这是我目前的应用程序-
如果用户未通过身份验证,它会呈现一个按钮,如果用户通过身份验证,它会呈现 Web 视图。
我想知道是否有任何方法可以在身份验证对话框启动时开始加载 Web 视图以加快进程?
class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
bool isAuthenticated = false;
@override
void initState() {
super.initState();
authenticate();
}
void authenticate() async {
bool authenticate = await LocalAuthApi.authenticate();
setState(() {
isAuthenticated = authenticate;
});
}
Widget build(BuildContext context) {
return isAuthenticated
? (Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'www.website.com',
)),
))
: (Scaffold(
body: Center(
child: FlatButton(
color: Colors.blue,
textColor: Colors.white,
padding: EdgeInsets.all(16.0),
onPressed: () {
authenticate();
},
child:
Text("Authenticate", style: TextStyle(fontSize: 15.0)),
),
)));
}
}