我正在使用flutter webview_flutter软件包。
现在我在主_controller
中有一个webview _MyAppState
变量。
“ _ MyAppState”类具有子窗口小部件QRCodeScannerPage()
。
在QRCodeScannerPage()
内,我有一个onTap函数。通过此功能,我想更改状态并调用_controller.load()
。但是如何访问_controller
?
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _selectedTab = 0;
bool _webView = false;
WebViewController _controller;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
primaryColor: Colors.black,
accentColor: Color(0xFF4054b2),
// primarySwatch: Colors.purple,
primaryTextTheme: TextTheme(
title: TextStyle(color: Colors.white),
)),
title: _title,
home: Scaffold(
key: _scaffoldKey,
appBar: new AppBar(
title: const Text('Clubs & Classes'),
),
body: IndexedStack(
index: _stackToView,
children: [
Column(
children: <Widget>[
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url,
onPageFinished: _handleLoad,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
},
)),
],
),
Container(
color: Colors.white,
child: Center(
child: CircularProgressIndicator(),
),
),
QRCodeScannerPage()
],
),
bottomNavigationBar: BottomNavigationBar(
// code...
),
);
}