Created
August 10, 2019 08:44
-
-
Save juliuscanute/9ac43b71efdafec96deec7ec9215bd8e to your computer and use it in GitHub Desktop.
[Creating a Stateless Widget] #flutter #dart #stateless-widget #ontap #inkwell #icon
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
//SYNTAX | |
class $1 extends StatelessWidget { | |
final T1 v1; | |
var T2 v2; | |
const $1({ | |
Key key, | |
@required this.v1, | |
this.v2, | |
}) : assert( v1 != null ), | |
super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Widget(); | |
} | |
} | |
//EXAMPLE | |
class Category extends StatelessWidget { | |
final String name; | |
final ColorSwatch color; | |
final IconData iconLocation; | |
const Category({ | |
Key key, | |
@required this.name, | |
@required this.color, | |
@required this.iconLocation, | |
}) : assert(name != null), | |
assert(color != null), | |
assert(iconLocation != null), | |
super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
color: Colors.transparent, | |
child: Container( | |
height: _rowHeight, | |
child: InkWell( | |
borderRadius: _borderRadius, | |
highlightColor: color, | |
splashColor: color, | |
onTap: () { | |
print('I was tapped!'); | |
}, | |
child: Padding( | |
padding: EdgeInsets.all(8.0), | |
child: Row( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: [ | |
Padding( | |
padding: EdgeInsets.all(16.0), | |
child: Icon( | |
iconLocation, | |
size: 60.0, | |
), | |
), | |
Center( | |
child: Text( | |
name, | |
textAlign: TextAlign.center, | |
style: Theme.of(context).textTheme.headline, | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment