Skip to content

Instantly share code, notes, and snippets.

@vijayinyoutube
Created January 15, 2020 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayinyoutube/f5e633707cbd5880ac632877a712e490 to your computer and use it in GitHub Desktop.
Save vijayinyoutube/f5e633707cbd5880ac632877a712e490 to your computer and use it in GitHub Desktop.
Flutter Buttons
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