Skip to content

Instantly share code, notes, and snippets.

@happyharis
Created January 4, 2021 04:41
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 happyharis/472a004b5b751610a243a1363b74b97f to your computer and use it in GitHub Desktop.
Save happyharis/472a004b5b751610a243a1363b74b97f to your computer and use it in GitHub Desktop.
flutter workshop 2021 source code
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