Skip to content

Instantly share code, notes, and snippets.

@dolpheen
Created January 10, 2021 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolpheen/95e6f965eaf29dfc40967a3a2151a388 to your computer and use it in GitHub Desktop.
Save dolpheen/95e6f965eaf29dfc40967a3a2151a388 to your computer and use it in GitHub Desktop.
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