Skip to content

Instantly share code, notes, and snippets.

@dolpheen
Created Jan 10, 2021
Embed
What would you like to do?
Futter hack sample demo
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static const String _title = 'Super App';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(
title: const Text(_title),
backgroundColor: Colors.blue,
),
body: const MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
// Our secret password
const _secret = 'secret';
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your password',
),
validator: (value) {
if (value != _secret) {
return 'Wrong password';
}
return null;
},
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
showDialog(
context: context,
builder: (context) => Center(
child: Card(
color: Colors.white,
child: Container(
padding: const EdgeInsets.fromLTRB(80, 20, 80, 20),
child: const Text(
'You are in !!!',
style: TextStyle(fontSize: 30),
),
),
),
),
);
}
},
child: const Text('Submit'),
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment