Created
June 9, 2024 22:44
-
-
Save ashraf267/8afd3a562ccb8650de7b16b7cba49026 to your computer and use it in GitHub Desktop.
enable or disable btn flutter snippet code
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(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
MyApp({super.key}); | |
@override | |
State<MyApp> createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> { | |
final myController = TextEditingController(); | |
bool enable = false; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: Column( | |
children: [ | |
SizedBox( | |
width: 200, | |
child: TextField( | |
cursorColor: Colors.red, | |
controller: myController, | |
onChanged: (val) { | |
if (myController.text.isNotEmpty) { | |
enable = true; | |
} else { | |
enable = false; | |
} | |
setState(() { | |
// | |
}); | |
}), | |
), | |
SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: (enable) | |
? () { | |
print(myController.text); | |
} | |
: null, | |
child: Text('login'), | |
), | |
SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: null, | |
child: Text('sign-in'), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment