Created
July 10, 2021 04:44
-
-
Save dhruvilp/cf78c681c6088bcdff45622a57cbc0f2 to your computer and use it in GitHub Desktop.
Elevated Buttons - Flutter
This file contains hidden or 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
/// Flutter code sample for SwitchListTile | |
//  | |
// | |
// This widget shows a switch that, when toggled, changes the state of a [bool] | |
// member field called `_lights`. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
/// This is the main application widget. | |
class MyApp extends StatelessWidget { | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: MyStatefulWidget(), | |
); | |
} | |
} | |
/// This is the stateful widget that the main application instantiates. | |
class MyStatefulWidget extends StatefulWidget { | |
MyStatefulWidget({Key? key}) : super(key: key); | |
@override | |
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); | |
} | |
/// This is the private State class that goes with MyStatefulWidget. | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
var _lights = false; | |
Widget _mainCard(String cardText, IconData cardIcon) { | |
return Expanded( | |
child: Padding( | |
padding: const EdgeInsets.all(15.0), | |
child: ElevatedButton.icon( | |
icon: Icon(cardIcon, size: 40.0), | |
label: Padding( | |
padding: const EdgeInsets.only(left: 15.0), | |
child: Text( | |
cardText, | |
style: TextStyle( | |
fontSize: 20.0, | |
), | |
), | |
), | |
onPressed: () {}, | |
style: ButtonStyle( | |
padding: MaterialStateProperty.all<EdgeInsetsGeometry>( | |
EdgeInsets.all(40.0), | |
), | |
shape: MaterialStateProperty.all<OutlinedBorder>( | |
RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(30.0), | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: !_lights ? Colors.white : Colors.grey.shade900, | |
appBar: AppBar(title: const Text(MyApp._title)), | |
body: Center( | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
_mainCard('UNLOCK DOORS', Icons.lock_open), | |
_mainCard('START ENGINE', Icons.power_settings_new), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment