Skip to content

Instantly share code, notes, and snippets.

@fwfurtado
Created April 6, 2022 21:03
Show Gist options
  • Save fwfurtado/ad437081113183d481144e14d6e381ba to your computer and use it in GitHub Desktop.
Save fwfurtado/ad437081113183d481144e14d6e381ba to your computer and use it in GitHub Desktop.
InkWellButton
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static const String _title = 'Flutter Code Sample';
var text = "";
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(
title: Row(
children: [
const Text(_title),
const SizedBox(
width: 20,
),
Expanded(
child: TextField(
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: "Enter text here...",
),
onChanged: (value) => setState(
() {
text = value;
},
),
),
)
],
),
),
body: Center(
child: MyButton(
onTap: text.isNotEmpty ? () {} : null,
),
),
),
);
}
}
class MyButton extends StatelessWidget {
final void Function()? onTap;
const MyButton({Key? key, this.onTap}) : super(key: key);
@override
Widget build(BuildContext context) {
return SizedBox(
width: 40,
height: 40,
child: Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
type: MaterialType.button,
color: onTap == null ? Colors.grey : Colors.deepPurple,
child: InkWell(
child: Icon(
Icons.send,
color: onTap == null ? Colors.grey[400] : Colors.white,
),
onTap: onTap,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment