Enable Disable Javascript Flutter WebView
Step 1 We cannot directly remove the time stamp from Enable Disable Javascript Flutter WebView but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .
dependencies:
flutter:
sdk: flutter
webview_flutter: ^1.0.7
flutter pub get
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _isJSEnabled = false;
_onChanged() {
setState(() {
_isJSEnabled = !_isJSEnabled;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.indigo,
title: Text("Enable / Disable JS In WEbview")),
body: Stack(
children: [
WebView(
initialUrl: 'https://bajarangisoft.com',
javascriptMode: _isJSEnabled
? JavascriptMode.unrestricted
: JavascriptMode.disabled,
),
Positioned(
child: Align(
alignment: Alignment.bottomCenter,
child: RaisedButton(
child: Text(_isJSEnabled ? "Disable JS" : "Enable JS"),
color: Colors.indigo,
textColor: Colors.white,
onPressed: _onChanged,
),
),
),
],
),
);
}
}