Created
April 6, 2022 21:03
-
-
Save fwfurtado/ad437081113183d481144e14d6e381ba to your computer and use it in GitHub Desktop.
InkWellButton
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
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