Last active
July 18, 2019 13:32
-
-
Save bugudiramu/a744178468469b3748c415256e73514d to your computer and use it in GitHub Desktop.
allaboutflutter blog Todo project app source code.
This file contains 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:allaboutflutterblog/projects/todo/homePage.dart'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
theme: defaultTargetPlatform == TargetPlatform.iOS | |
? ThemeData.dark() | |
: ThemeData.light(), | |
home: HomePage(), | |
debugShowCheckedModeBanner: false, | |
), | |
); | |
} | |
import 'package:flutter/material.dart'; | |
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
GlobalKey<FormState> _key = GlobalKey<FormState>(); | |
TextEditingController _controller = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Todo"), | |
centerTitle: true, | |
backgroundColor: Color(0XFF34495e), | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(10.0), | |
), | |
), | |
body: Container(), | |
floatingActionButton: FloatingActionButton( | |
tooltip: "Add Todo", | |
child: Icon(FontAwesomeIcons.plus), | |
backgroundColor: Color(0XFF34495e), | |
onPressed: () => _showDialog(), | |
), | |
); | |
} | |
_showDialog() { | |
var alert = AlertDialog( | |
elevation: 10.0, | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(10.0), | |
), | |
content: ListTile( | |
title: Container( | |
child: Text( | |
"Add Todo".toUpperCase(), | |
style: TextStyle( | |
color: Colors.grey, | |
fontWeight: FontWeight.bold, | |
fontSize: 18.0, | |
), | |
), | |
), | |
subtitle: Form( | |
key: _key, | |
autovalidate: true, | |
child: TextFormField( | |
controller: _controller, | |
decoration: InputDecoration( | |
hintText: "Enter A Todo", | |
alignLabelWithHint: true, | |
icon: Icon(FontAwesomeIcons.drupal), | |
), | |
validator: (val) { | |
if (val.isEmpty) { | |
return "Please Enter A Task"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_controller.text = val; | |
}, | |
), | |
), | |
), | |
actions: <Widget>[ | |
Row( | |
children: <Widget>[ | |
FlatButton( | |
child: Text( | |
"Cancel".toUpperCase(), | |
style: TextStyle( | |
color: Colors.grey, | |
fontWeight: FontWeight.bold, | |
fontSize: 18.0, | |
), | |
), | |
onPressed: () => Navigator.of(context).pop(), | |
), | |
FlatButton( | |
child: Text( | |
"Add".toUpperCase(), | |
style: TextStyle( | |
color: Color(0XCC27ae60), | |
fontWeight: FontWeight.bold, | |
fontSize: 18.0, | |
), | |
), | |
onPressed: () { | |
_validateForm(); | |
}, | |
), | |
], | |
) | |
], | |
); | |
showDialog( | |
context: context, | |
builder: (context) => alert, | |
); | |
} | |
_validateForm() { | |
if (_key.currentState.validate()) { | |
_key.currentState.save(); | |
_controller.clear(); | |
Navigator.of(context).pop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment