Skip to content

Instantly share code, notes, and snippets.

@leighajarett
Created November 7, 2022 22:22
Show Gist options
  • Select an option

  • Save leighajarett/4d458ed327a365e5c857e1fe614d0438 to your computer and use it in GitHub Desktop.

Select an option

Save leighajarett/4d458ed327a365e5c857e1fe614d0438 to your computer and use it in GitHub Desktop.
Flutter open app example
import 'package:flutter/cupertino.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(
const App(),
);
}
class App extends StatelessWidget {
const App({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return const CupertinoApp(
theme: CupertinoThemeData(brightness: Brightness.dark),
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: SafeArea(
child: Center(
child:
// #docregion OpenAppExample
CupertinoButton(
onPressed: () async {
await launchUrl(
Uri.parse('https://google.com'),
);
},
child: const Text(
'Open website',
),
),
// #enddocregion OpenAppExample
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment