Skip to content

Instantly share code, notes, and snippets.

@andrea689
Last active April 11, 2019 13:11
Show Gist options
  • Save andrea689/5ff5b43506316fa9807de79b85d8996c to your computer and use it in GitHub Desktop.
Save andrea689/5ff5b43506316fa9807de79b85d8996c to your computer and use it in GitHub Desktop.
[bug][ios] UiKitView and url_launcher conflict
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
backgroundColor: Colors.blue,
body: Column(
children: <Widget>[
Container(
height: 400,
child: WebView(
initialUrl: "https://google.com/"
),
),
RaisedButton(
child: Text("launch url"),
onPressed: () => _launchUrl('https://flutter.dev'),
),
RaisedButton(
child: Text("new page"),
onPressed: () => _pushPage(context),
)
]
)
);
}
}
class MySecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RaisedButton(
onPressed: () => _launchUrl('https://flutter.dev'),
child: Text('Launch url'),
),
RaisedButton(
child: Text("new page"),
onPressed: () => _pushPage(context),
)
]
);
}
}
void _launchUrl(String url) async {
if (await canLaunch(url)) {
await launch(url, forceSafariVC: true);
} else {
throw 'Could not launch $url';
}
}
void _pushPage(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => Scaffold(
appBar: AppBar(title: Text("Tittle")),
body: MySecondPage(),
)
)
);
}
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:async';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _showWebView = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
backgroundColor: Colors.blue,
body: Column(
children: <Widget>[
Container(
width: double.infinity,
height: 400,
child: _showWebView ? WebView(
initialUrl: "https://google.com/"
) : Text("Waiting"),
),
RaisedButton(
child: Text("launch url"),
onPressed: () => _launchUrl('https://flutter.dev'),
),
RaisedButton(
child: Text("new page"),
onPressed: () async {
Timer(Duration(milliseconds: 500), (){
setState(() {
_showWebView = false;
});
});
await _pushPage(context);
setState(() {
_showWebView = true;
});
},
)
]
)
);
}
}
class MySecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RaisedButton(
onPressed: () => _launchUrl('https://flutter.dev'),
child: Text('Launch url'),
),
RaisedButton(
child: Text("new page"),
onPressed: () => _pushPage(context),
)
]
);
}
}
void _launchUrl(String url) async {
if (await canLaunch(url)) {
await launch(url, forceSafariVC: true);
} else {
throw 'Could not launch $url';
}
}
Future<void> _pushPage(BuildContext context) {
return Navigator.of(context).push(MaterialPageRoute<void>(
builder: (_) => Scaffold(
appBar: AppBar(title: Text("Tittle")),
body: MySecondPage(),
),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment