flutter_simple_webview 0.0.1 copy "flutter_simple_webview: ^0.0.1" to clipboard
flutter_simple_webview: ^0.0.1 copied to clipboard

A Flutter package to easily display web content from a given URL with built-in internet connectivity checks and error handling.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_simple_webview/flutter_simple_webview.dart'; // Import your package

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false, // Hides the debug banner
      title: 'Flutter Simple WebView Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        appBarTheme: const AppBarTheme(
          backgroundColor: Colors.blue, // Consistent AppBar color
          foregroundColor: Colors.white, // AppBar text/icon color
        ),
      ),
      home: const HomeScreen(), // Use a dedicated screen for better structure
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final TextEditingController _urlController = TextEditingController();
  String _currentUrl = "https://www.google.com/"; // Initial URL

  @override
  void initState() {
    super.initState();
    _urlController.text = _currentUrl; // Set initial text in controller
  }

  @override
  void dispose() {
    _urlController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter Simple WebView Example'),
        centerTitle: true,
      ),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              children: [
                Expanded(
                  child: TextField(
                    controller: _urlController,
                    decoration: const InputDecoration(
                      labelText: 'Enter URL',
                      border: OutlineInputBorder(),
                    ),
                    keyboardType: TextInputType.url,
                    onSubmitted: (url) {
                      setState(() {
                        _currentUrl = url;
                      });
                    },
                  ),
                ),
                const SizedBox(width: 8),
                ElevatedButton(
                  onPressed: () {
                    setState(() {
                      _currentUrl = _urlController.text;
                    });
                  },
                  child: const Text('Go'),
                ),
              ],
            ),
          ),
          Expanded(
            child: FlutterSimpleWebView(
              url: _currentUrl, // Use the dynamic URL
              appBarTitle:
                  "Loaded Content", // Can be dynamic based on current URL if preferred
              showAppBar: true, // Example of showing the app bar
              backgroundColor: Colors.white,
              progressColor: Colors.amber, // Example custom progress color
              onPageStarted: (url) {
                debugPrint('Example: Page started loading: $url');
              },
              onPageFinished: (url) {
                debugPrint('Example: Page finished loading: $url');
              },
              onWebResourceError: (error) {
                debugPrint('Example: Web resource error: ${error.description}');
              },
            ),
          ),
        ],
      ),
    );
  }
}
4
likes
160
points
38
downloads

Publisher

verified publisherrahulreza.com

Weekly Downloads

A Flutter package to easily display web content from a given URL with built-in internet connectivity checks and error handling.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, flutter, fluttertoast, url_launcher, webview_flutter

More

Packages that depend on flutter_simple_webview