Skip to content

Instantly share code, notes, and snippets.

@theindianappguy
Created October 4, 2020 15:35
Show Gist options
  • Save theindianappguy/2cd8a05ecf0e4288b2f73b8455a35dd6 to your computer and use it in GitHub Desktop.
Save theindianappguy/2cd8a05ecf0e4288b2f73b8455a35dd6 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class RecipeView extends StatefulWidget {
final String postUrl;
RecipeView({@required this.postUrl});
@override
_RecipeViewState createState() => _RecipeViewState();
}
class _RecipeViewState extends State<RecipeView> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
String finalUrl ;
@override
void initState() {
// TODO: implement initState
super.initState();
finalUrl = widget.postUrl;
if(widget.postUrl.contains('http://')){
finalUrl = widget.postUrl.replaceAll("http://","https://");
print(finalUrl + "this is final url");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: Platform.isIOS? 60: 30, right: 24,left: 24,bottom: 16),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xff213A50),
const Color(0xff071930)
],
begin: FractionalOffset.topRight,
end: FractionalOffset.bottomLeft)),
child: Row(
mainAxisAlignment: kIsWeb
? MainAxisAlignment.start
: MainAxisAlignment.center,
children: <Widget>[
Text(
"AppGuy",
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontFamily: 'Overpass'),
),
Text(
"Recipes",
style: TextStyle(
fontSize: 18,
color: Colors.blue,
fontFamily: 'Overpass'),
)
],
),
),
Container(
height: MediaQuery.of(context).size.height - (Platform.isIOS ? 104 : 30),
width: MediaQuery.of(context).size.width,
child: WebView(
onPageFinished: (val){
print(val);
},
javascriptMode: JavascriptMode.unrestricted,
initialUrl: finalUrl,
onWebViewCreated: (WebViewController webViewController){
setState(() {
_controller.complete(webViewController);
});
},
),
),
],
),
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment