@@ -65,6 +65,19 @@ class _MyHomePageState extends State<MyHomePage> {
6565 }
6666 }
6767
68+ Future <void > _launchInWebViewWithDomStorage (String url) async {
69+ if (await canLaunch (url)) {
70+ await launch (
71+ url,
72+ forceSafariVC: true ,
73+ forceWebView: true ,
74+ enableDomStorage: true ,
75+ );
76+ } else {
77+ throw 'Could not launch $url ' ;
78+ }
79+ }
80+
6881 Future <void > _launchUniversalLinkIos (String url) async {
6982 if (await canLaunch ('https://youtube.com' )) {
7083 final bool nativeAppLaunchSucceeded = await launch (
@@ -104,69 +117,77 @@ class _MyHomePageState extends State<MyHomePage> {
104117 appBar: AppBar (
105118 title: Text (widget.title),
106119 ),
107- body: Center (
108- child: Column (
109- mainAxisAlignment: MainAxisAlignment .center,
110- children: < Widget > [
111- Padding (
112- padding: const EdgeInsets .all (16.0 ),
113- child: TextField (
114- onChanged: (String text) => _phone = text,
115- decoration: const InputDecoration (
116- hintText: 'Input the phone number to launch' )),
117- ),
118- RaisedButton (
119- onPressed: () => setState (() {
120- _launched = _makePhoneCall ('tel:$_phone ' );
121- }),
122- child: const Text ('Make phone call' ),
123- ),
124- const Padding (
125- padding: EdgeInsets .all (16.0 ),
126- child: Text (toLaunch),
127- ),
128- RaisedButton (
129- onPressed: () => setState (() {
130- _launched = _launchInBrowser (toLaunch);
131- }),
132- child: const Text ('Launch in browser' ),
133- ),
134- const Padding (padding: EdgeInsets .all (16.0 )),
135- RaisedButton (
136- onPressed: () => setState (() {
137- _launched = _launchInWebViewOrVC (toLaunch);
138- }),
139- child: const Text ('Launch in app' ),
140- ),
141- const Padding (padding: EdgeInsets .all (16.0 )),
142- RaisedButton (
143- onPressed: () => setState (() {
144- _launched = _launchInWebViewWithJavaScript (toLaunch);
145- }),
146- child: const Text ('Launch in app(JavaScript ON)' ),
147- ),
148- RaisedButton (
149- onPressed: () => setState (() {
150- _launched = _launchUniversalLinkIos (toLaunch);
151- }),
152- child: const Text (
153- 'Launch a universal link in a native app, fallback to Safari.(Youtube)' ),
154- ),
155- const Padding (padding: EdgeInsets .all (16.0 )),
156- RaisedButton (
157- onPressed: () => setState (() {
158- _launched = _launchInWebViewOrVC (toLaunch);
159- Timer (const Duration (seconds: 5 ), () {
160- print ('Closing WebView after 5 seconds...' );
161- closeWebView ();
162- });
163- }),
164- child: const Text ('Launch in app + close after 5 seconds' ),
165- ),
166- const Padding (padding: EdgeInsets .all (16.0 )),
167- FutureBuilder <void >(future: _launched, builder: _launchStatus),
168- ],
169- ),
120+ body: ListView (
121+ children: < Widget > [
122+ Column (
123+ mainAxisAlignment: MainAxisAlignment .center,
124+ children: < Widget > [
125+ Padding (
126+ padding: const EdgeInsets .all (16.0 ),
127+ child: TextField (
128+ onChanged: (String text) => _phone = text,
129+ decoration: const InputDecoration (
130+ hintText: 'Input the phone number to launch' )),
131+ ),
132+ RaisedButton (
133+ onPressed: () => setState (() {
134+ _launched = _makePhoneCall ('tel:$_phone ' );
135+ }),
136+ child: const Text ('Make phone call' ),
137+ ),
138+ const Padding (
139+ padding: EdgeInsets .all (16.0 ),
140+ child: Text (toLaunch),
141+ ),
142+ RaisedButton (
143+ onPressed: () => setState (() {
144+ _launched = _launchInBrowser (toLaunch);
145+ }),
146+ child: const Text ('Launch in browser' ),
147+ ),
148+ const Padding (padding: EdgeInsets .all (16.0 )),
149+ RaisedButton (
150+ onPressed: () => setState (() {
151+ _launched = _launchInWebViewOrVC (toLaunch);
152+ }),
153+ child: const Text ('Launch in app' ),
154+ ),
155+ RaisedButton (
156+ onPressed: () => setState (() {
157+ _launched = _launchInWebViewWithJavaScript (toLaunch);
158+ }),
159+ child: const Text ('Launch in app(JavaScript ON)' ),
160+ ),
161+ RaisedButton (
162+ onPressed: () => setState (() {
163+ _launched = _launchInWebViewWithDomStorage (toLaunch);
164+ }),
165+ child: const Text ('Launch in app(DOM storage ON)' ),
166+ ),
167+ const Padding (padding: EdgeInsets .all (16.0 )),
168+ RaisedButton (
169+ onPressed: () => setState (() {
170+ _launched = _launchUniversalLinkIos (toLaunch);
171+ }),
172+ child: const Text (
173+ 'Launch a universal link in a native app, fallback to Safari.(Youtube)' ),
174+ ),
175+ const Padding (padding: EdgeInsets .all (16.0 )),
176+ RaisedButton (
177+ onPressed: () => setState (() {
178+ _launched = _launchInWebViewOrVC (toLaunch);
179+ Timer (const Duration (seconds: 5 ), () {
180+ print ('Closing WebView after 5 seconds...' );
181+ closeWebView ();
182+ });
183+ }),
184+ child: const Text ('Launch in app + close after 5 seconds' ),
185+ ),
186+ const Padding (padding: EdgeInsets .all (16.0 )),
187+ FutureBuilder <void >(future: _launched, builder: _launchStatus),
188+ ],
189+ ),
190+ ],
170191 ),
171192 );
172193 }
0 commit comments