Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created November 23, 2021 17:04
Show Gist options
  • Save doyle-flutter/0200919d654d7d5ef872348b8e1f4a44 to your computer and use it in GitHub Desktop.
Save doyle-flutter/0200919d654d7d5ef872348b8e1f4a44 to your computer and use it in GitHub Desktop.
(1) net::ERR_UNKNOWN_URL_SCHEME
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(Sys());
class Sys extends StatelessWidget {
const Sys({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
onGenerateRoute: (RouteSettings route) => MaterialPageRoute(
settings: RouteSettings(name: MainPage.path),
builder: (context) => MainPage()
),
);
}
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
static const String path = "/";
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
bool check = false;
/// net::ERR_UNKNOWN_URL_SCHEME
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(),
body: this.check ? Center(child: Text("Load")) : WebView(
initialUrl: "http://192.168.25.46:3000",
javascriptMode: JavascriptMode.unrestricted,
onPageStarted: (String url){
print("📌");
/// Example
// if(url.indexOf("inapt://") >= 0){
// try{
// await launch(url);
// }
// catch(e){}
// }
/// TEST
if(url.indexOf("sms") >= 0){
setState(() => this.check = true);
try{ launch(url); }
catch(e){}
}
}
),
floatingActionButton: !this.check
? null
: FloatingActionButton(
child: Icon(Icons.check),
onPressed: () => setState(() => this.check = false)
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment