juliuscanute
8/10/2019 - 8:44 AM

[Creating a Stateless Widget] #flutter #dart #stateless-widget #ontap #inkwell #icon

[Creating a Stateless Widget] #flutter #dart #stateless-widget #ontap #inkwell #icon

//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,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}