Created
January 4, 2021 04:41
-
-
Save happyharis/472a004b5b751610a243a1363b74b97f to your computer and use it in GitHub Desktop.
flutter workshop 2021 source code
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData(primarySwatch: Colors.indigo), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final todos = <String>['Learn Flutter', 'Create Todo App']; | |
final textController = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('My Todos'), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(18.0), | |
child: Column( | |
children: [ | |
TextField( | |
controller: textController, | |
decoration: InputDecoration(border: OutlineInputBorder()), | |
), | |
for (var todo in todos) | |
ListTile( | |
leading: Text(todo), | |
trailing: OutlinedButton( | |
onPressed: () => setState(() => todos.remove(todo)), | |
child: Text('Done'), | |
), | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
if (textController.text.isEmpty) { | |
showDialog( | |
context: context, | |
builder: (context) { | |
return AlertDialog( | |
title: Text('Please enter some text 🥺'), | |
); | |
}, | |
); | |
} else { | |
setState(() { | |
todos.add(textController.text); | |
textController.clear(); | |
}); | |
} | |
}, | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment