Flutter WebView Plugin - How To Handle Local Stora

2019-07-08 05:19发布

问题:

Background: I am working on a mobile application in which I use a WebViewScaffold to load an online directory. This particular directory provides a guided tour on initial visit.

Problem: Each time I navigate to the directory WebView, the tour starts from the beginning (which freezes the user until the tour is finished). How might I keep this from happening? When I open the directory in a browser, the status of the tour is saved in the browser's local storage variables. Is there a way to save or reset the local storage variables in flutter?

Code: Upon button click, I push a new route where I create a new Directory object which is shown below:

class MobileDirectory extends StatelessWidget {
  final _mobileDirectory = 'my.mobileDirectory.url';
  final _directoryTitle = new Text(
    'Directory',
    style: const TextStyle(
        fontSize: 17.0, color: Colors.white, fontWeight: FontWeight.w400),
  );
  final _backgroundColor = new Color.fromRGBO(29, 140, 186, 1.0);
  final _backButton = new BackButton(color: Colors.white);
  final _padding = new EdgeInsets.only(left: 2.0);
  final _imageAsset = new Image.asset('assets/appBar.jpg');

  @override
  Widget build(BuildContext context) {
    return new WebviewScaffold(
      appBar: new AppBar(
        leading: _backButton,
        centerTitle: true,
        backgroundColor: _backgroundColor,
        title: new Padding(
          padding: _padding,
          child: _directoryTitle,
        ),
        actions: <Widget>[
          _imageAsset,
        ],
      ),
      url: _mobileDirectory,
    );
  }
}

Note: Please let me know if more information should be provided.

回答1:

The most recent version 0.1.4 supports using localstorage

https://github.com/dart-flitter/flutter_webview_plugin/blob/9873b2d9a2167f76018d4f6e7fc6e2a1ed8ce5c9/lib/src/webview_scaffold.dart#L35