Skip to content

Instantly share code, notes, and snippets.

@Norbert515
Created November 9, 2019 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Norbert515/4aae82797f57ff7a28891a0381fefa77 to your computer and use it in GitHub Desktop.
Save Norbert515/4aae82797f57ff7a28891a0381fefa77 to your computer and use it in GitHub Desktop.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;
class TodoModel {
String title;
String date;
bool done;
TodoModel({
@required this.title,
@required this.date,
@required this.done
});
}
void main() {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.orange,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<TodoModel> models = [
TodoModel(
done: false,
title: "Some title",
date: "Some date"
),
TodoModel(
done: false,
title: "Some title",
date: "Some date"
),
TodoModel(
done: true,
title: "other stuff",
date: "Some date"
),
TodoModel(
done: false,
title: "Some title",
date: "Some date"
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("GDG-Devfest super ToDo App"),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
print("Pressed the button!");
},
child: Icon(Icons.add,color: Colors.white,),
),
body: ListView.builder(
itemCount: models.length,
itemBuilder: (context, index) {
return TodoItem(
todoModel: models[index],
onChanged: (done) {
models[index].done = done;
setState(() {});
},
);
},
),
);
}
}
class TodoItem extends StatelessWidget {
final TodoModel todoModel;
final ValueChanged<bool> onChanged;
const TodoItem({
Key key,
@required this.todoModel,
@required this.onChanged
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(todoModel.title,
style: TextStyle(
color: todoModel.done? Colors.red : Colors.black,
decoration: todoModel.done? TextDecoration.lineThrough : null
),
),
subtitle: Text(todoModel.date),
trailing: Checkbox(
value: todoModel.done,
onChanged: onChanged,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment