flutter_simple_webview 2.0.0
flutter_simple_webview: ^2.0.0 copied to clipboard
A production-grade, zero-dependency Flutter WebView package with advanced features like file upload, background download, and cookie persistence.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_simple_webview/flutter_simple_webview.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SimpleWebView Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final TextEditingController _urlController = TextEditingController(
text: 'https://flutter.dev',
);
WebViewController? _controller;
String _status = "Loading...";
bool _canGoBack = false;
bool _canGoForward = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SimpleWebView Demo'),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(48),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
controller: _urlController,
decoration: const InputDecoration(
hintText: 'Enter URL',
contentPadding: EdgeInsets.symmetric(horizontal: 10),
border: OutlineInputBorder(),
),
onSubmitted: (val) {
if (_controller != null) {
_controller!.loadUrl(val);
}
},
),
),
IconButton(
icon: const Icon(Icons.arrow_forward),
onPressed: () {
if (_controller != null) {
_controller!.loadUrl(_urlController.text);
}
},
),
],
),
),
),
),
body: Column(
children: [
Container(
padding: const EdgeInsets.all(8),
color: Colors.grey[200],
child: Row(
children: [
Text("Status: $_status"),
const Spacer(),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => _controller?.reload(),
),
IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: _canGoBack ? () => _controller?.goBack() : null,
),
IconButton(
icon: const Icon(Icons.arrow_forward),
onPressed: _canGoForward
? () => _controller?.goForward()
: null,
),
],
),
),
Expanded(
child: SimpleWebView(
url: _urlController.text,
showAppBar: false, // We are using our own AppBar
onWebViewCreated: (controller) {
_controller = controller;
},
onConnectivityChanged: (connected) {
setState(() {
_status = connected ? "Online" : "Offline";
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
connected ? "Connected" : "No Internet Connection",
),
backgroundColor: connected ? Colors.green : Colors.red,
),
);
},
onMessageReceived: (message) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text("JS Message: $message")));
},
),
),
],
),
);
}
}