Skip to content

Instantly share code, notes, and snippets.

@CoderNamedHendrick
Created July 10, 2023 03:18
Show Gist options
  • Save CoderNamedHendrick/c99243804293f86eca39bbeace184b57 to your computer and use it in GitHub Desktop.
Save CoderNamedHendrick/c99243804293f86eca39bbeace184b57 to your computer and use it in GitHub Desktop.
My Home Page
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