import
'package:flutter/material.dart'
;
void
main() => runApp(MyApp());
class
MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'GeeksforGeeks'
,
debugShowCheckedModeBanner:
false
,
theme: ThemeData(
primarySwatch: Colors.green,
),
home: ButtonsExample(),
);
}
}
class
ButtonsExample extends StatelessWidget {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
void
textButtonHandler() {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
'Text/ Flat Button'
),
duration: Duration(seconds: 1),
),
);
}
void
elevatedButtonHandler() {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
'Elevated/ Raised Button'
),
duration: Duration(seconds: 1),
),
);
}
void
outlineButtonHandler() {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
'Outline/ Outlined Button'
),
duration: Duration(seconds: 1),
),
);
}
void
iconButtonHandler() {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
'Icon Button'
),
duration: Duration(seconds: 1),
),
);
}
void
floatingActionButtonHandler() {
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text(
'Floating Action Button'
),
duration: Duration(seconds: 1),
),
);
}
@override
Widget build(BuildContext context) {
return
SafeArea(
child: Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text(
'GeeksforGeeks'
),
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextButton(
onPressed: textButtonHandler,
child: Text(
'Text Button'
),
),
FlatButton(
minWidth: MediaQuery.of(context).size.width,
onPressed: textButtonHandler,
child: Text(
'Flat Button'
),
),
ElevatedButton(
onPressed: elevatedButtonHandler,
child: Text(
'Elevated Button'
),
),
RaisedButton(
onPressed: elevatedButtonHandler,
child: Text(
'Raised Button'
),
),
OutlineButton(
onPressed: outlineButtonHandler,
child: Text(
'Outline Button'
),
),
OutlinedButton(
onPressed: outlineButtonHandler,
child: Text(
'Outlined Button'
),
),
IconButton(
icon: Icon(Icons.star),
onPressed: iconButtonHandler,
),
FloatingActionButton.extended(
onPressed: floatingActionButtonHandler,
label: Text(
'Floating Action Button'
),
),
],
),
),
),
);
}
}