//import 'package:modelo/funcoes_gerais.dart';
import 'package:flutter/material.dart';
//import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';

class InstagramScreen extends StatefulWidget {
  @override
  _InstagramScreenState createState() => _InstagramScreenState();
}

class _InstagramScreenState extends State<InstagramScreen>
    with AutomaticKeepAliveClientMixin<InstagramScreen> {
  bool error = false;
  String msg = '';
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return SafeArea(
      child: this.error
          ? this._buildError()
          : WebView(
              initialUrl: 'https://blog.hightechx.com/teste-feed-instagram/',
              javascriptMode: JavascriptMode.unrestricted,
              onWebResourceError: (err) {
                this.error = true;
                this.msg = err.description;
                setState(() {});
              },
              // navigationDelegate: (navigation){
              //   print(navigation.url);
              //   if (navigation.url.startsWith(FuncoesGerais.dominioPermitido)) {
              //     return NavigationDecision.navigate;
              //   }
              //   //print('allowing navigation to $request');
              //   launch(navigation.url);
              //   return NavigationDecision.prevent;
              // },
            ),
    );
  }

  Widget _buildError() {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(msg),
          ElevatedButton(
              onPressed: () {
                this.error = false;
                this.msg = '';
                setState(() {});
              },
              child: Text('Atualizar'))
          // RaisedButton(onPressed: (){
          //   this.error = false;
          //   this.msg = '';
          //   setState(() {
          //   });
          // }, child: Text('Atualizar'),)
        ],
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
