2
We can create a button with a Container
, so leave it as we wish.
My doubt, is in the touch effect with the InkWell
, that a color is added to the Container
, the same "stops working" as in the example:
Code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'InkWell Demo';
return MaterialApp(
title: title,
home: MyHomePage(title: title),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
MyHomePage({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(child: MyButton()),
);
}
}
class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
// The InkWell wraps the custom flat button widget.
return InkWell(
// When the user taps the button, show a snackbar.
onTap: () {
Scaffold.of(context).removeCurrentSnackBar();
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Tap'),
));
},
child: Container(
padding: EdgeInsets.all(12.0),
child: Text('Flat Button'),
color: Colors.blue,
),
);
}
}
Source: ripples
Doubts
- How can I "fix" this problem?
- What other alternatives are widgets for
buttom
customized?
One of the ways I tested was exactly this! I found here link. +1
– rbz
Yes exactly that! By doing so you achieve the expected effects
– Matheus Ribeiro
But using Container for custom buttons is still the best!? Considering a standardization, effects, etc..
– rbz
Response implemented, take a look.
– Matheus Ribeiro