simple_dark_mode_webview 0.2.0-nullsafety.1 copy "simple_dark_mode_webview: ^0.2.0-nullsafety.1" to clipboard
simple_dark_mode_webview: ^0.2.0-nullsafety.1 copied to clipboard

outdated

A simple implementation of dark mode or dark theme webview. The idea is very simple, this webview wraps the whole html text with a dark mode <body> tag.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:simple_dark_mode_webview/simpledarkmodewebview.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Simple Dark Mode Webview Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      // You need to set darkTheme here!
      darkTheme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.green,
      ),
      home: MyHomePage(title: 'Simple Dark Mode Webview Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              color: Colors.grey,
              child: Text(
                'This widget is useful specially when you want to show a static HTML file!!!',
              ),
            ),
            Expanded(
              child: FutureBuilder(
                future: rootBundle.loadString('lib/assets/sample_policy.html'),
                builder: (context, snapshot) {
                  if(!snapshot.hasData){
                    return Text('loading...');
                  } else {
                    return SimpleDarkModeAdaptableWebView(
                      snapshot.data,

                      // (Example) Specify the html's encoding.
                      encoding: Encoding.getByName('utf-8'),

                      // (Example) You can also register gestures as like the original webview.
                      gestureRecognizers: Set()
                        ..add(Factory<TapGestureRecognizer>(() =>
                        TapGestureRecognizer()
                          ..onTapDown = (tap) {
                            final snackBar = SnackBar(content: Text('Webivew was tapped down.'));
                            //Scaffold.of(context).showSnackBar(snackBar);
                            ScaffoldMessenger.of(context).showSnackBar(snackBar);
                          }
                        )
                      ),
                    );
                  }
                },
              )
            )
          ],
        ),
      ),
    );
  }
}
5
likes
0
pub points
33%
popularity

Publisher

verified publisherhilog07.blogspot.com

A simple implementation of dark mode or dark theme webview. The idea is very simple, this webview wraps the whole html text with a dark mode <body> tag.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, webview_flutter

More

Packages that depend on simple_dark_mode_webview