Created
July 10, 2023 03:18
-
-
Save CoderNamedHendrick/c99243804293f86eca39bbeace184b57 to your computer and use it in GitHub Desktop.
My Home Page
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
class MyHomePage extends StatefulWidget { | |
const MyHomePage({super.key, required this.title}); | |
final String title; | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final formKey = GlobalKey<FormState>(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
title: Text(widget.title), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Center( | |
child: Form( | |
key: formKey, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
ImagePickerField(), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
final isValid = formKey.currentState!.validate(); | |
if (isValid) { | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar( | |
backgroundColor: Colors.green, | |
content: Text( | |
'Form is valid', | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
); | |
} | |
}, | |
child: const Text('Validate Form'), | |
) | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment