In flutter, first I declare the varibale(late final WebViewController webViewController_;
)
and then execute webViewController_.runJavaScript("localStorage.setItem('test_val','test_val__')");
this code.
But runJavaScript doesn’t run. I tried another function that is included in webViewController(forexample clearLocalStorage, clearCache .. ) but all of this code also doesn’t run..
I think type(late final) cause the problem but I can’t convince.
So I wan’t to ask which code cause the problem in my code
The structure of code like this (code below)
import 'package:webview_flutter/webview_flutter.dart';
...
void main() async {
...
}
class TestApp extends StatelessWidget {
const TestApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => const TestPage(),
},
);
}
}
class TestPage extends StatefulWidget {
const TestPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _TESTPageState();
}
class _TESTPageState extends State<TMSPage> with WidgetsBindingObserver{
late final WebViewController webViewController_;
@override
void initState(){
super.initState();
}
...
@override
Widget build(BuildContext context) {
return WillPopScope(
print('in1'); // operated
// Below code occur the problem
webViewController_.runJavaScript("localStorage.setItem('test_val','test_val__')");
print('in2'); // not operated, not error occured, but progress is stop
return false;
},
child: Scaffold(
body: Center(
child: FutureBuilder<bool?>(
future: checkLogin(),
builder: (context, snapshot) {
if(Platform.isAndroid) {
if (snapshot.data == true) {
return const WebViewPage();
}else {
return SignIn();
}
}else if(Platform.isIOS){
if (snapshot.data == true) {
return const WebViewPage();
}else if (snapshot.data == null) {
return SignIn();
}else{
return const NullPage();
}
}else{
return const NullPage();
}
},
),
),
),
);
}
}