Instantly share code, notes, and snippets.
Created
January 15, 2020 14:30
Flutter Buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "package:flutter/material.dart"; | |
import "package:url_launcher/url_launcher.dart"; | |
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; | |
void main() { | |
runApp(MaterialApp(home: MyApp(), debugShowCheckedModeBanner: false)); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
@override | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: Center( | |
child: SingleChildScrollView( | |
child: Column( | |
children: <Widget>[ | |
SizedBox( | |
height: 50, | |
), | |
Text( | |
"Button Types in Flutter", | |
style: TextStyle( | |
fontSize: 30, | |
fontWeight: FontWeight.bold, | |
color: Colors.indigo), | |
), | |
SizedBox( | |
height: 30, | |
), | |
FlatButton( | |
color: Colors.green, | |
child: Text('FlatButton'), | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("You pressed FlatButton"), | |
actions: <Widget>[ | |
new FlatButton( | |
child: Icon( | |
Icons.check, | |
color: Colors.greenAccent, | |
size: 40, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
}, | |
), | |
SizedBox( | |
height: 30, | |
), | |
RaisedButton( | |
color: Colors.orange, | |
child: Text('RaisedButton'), | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("You pressed RaisedButton"), | |
actions: <Widget>[ | |
new FlatButton( | |
child: Icon( | |
Icons.check, | |
color: Colors.greenAccent, | |
size: 40, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
}, | |
), | |
SizedBox( | |
height: 30, | |
), | |
FloatingActionButton( | |
child: Icon(Icons.home), | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("You pressed FloatingButton"), | |
actions: <Widget>[ | |
new FlatButton( | |
child: Icon( | |
Icons.check, | |
color: Colors.greenAccent, | |
size: 40, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
}, | |
), | |
SizedBox( | |
height: 30, | |
), | |
FloatingActionButton.extended( | |
icon: Icon(Icons.home), | |
label: Text('<Extended>'), | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("You pressed Extended"), | |
actions: <Widget>[ | |
new FlatButton( | |
child: Icon( | |
Icons.check, | |
color: Colors.greenAccent, | |
size: 40, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
}, | |
), | |
SizedBox( | |
height: 30, | |
), | |
IconButton( | |
color: Colors.green, | |
icon: Icon(Icons.android), | |
onPressed: () { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
title: new Text("You pressed IconButton"), | |
actions: <Widget>[ | |
new FlatButton( | |
child: Icon( | |
Icons.check, | |
color: Colors.greenAccent, | |
size: 40, | |
), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
], | |
); | |
}, | |
); | |
}, | |
), | |
SizedBox( | |
height: 30, | |
), | |
InkWell( | |
onTap: launchURL, | |
child: Text("My Blog", | |
style: TextStyle( | |
color: Colors.blue, | |
fontSize: 13, | |
decoration: TextDecoration.underline)), | |
), | |
SizedBox( | |
height: 30, | |
), | |
GestureDetector( | |
onTap: launchURL, | |
child: Text("My Blog", | |
style: TextStyle( | |
color: Colors.blue, | |
fontSize: 13, | |
decoration: TextDecoration.underline)), | |
), | |
SizedBox( | |
height: 30, | |
), | |
], | |
), | |
), | |
)); | |
} | |
} | |
Future launchURL() async { | |
const url = | |
"https://docs.google.com/document/d/e/2PACX-1vR0QAa9MblK12fYEHB_flEsNRVqnvlcCIB9E9uRZs2Q5FYjHE0yFHIpcOSnhl88P26_2l4PJSR_T_A-/pub"; | |
if (await canLaunch(url)) { | |
await launch(url, forceSafariVC: true, forceWebView: true); | |
} else { | |
throw 'Could not launch $url'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment