Open name27 opened 1 year ago
ex)
enum NewColor {
red("레드", "red"),
blue("블루", "blue"),
white("화이트", "white"),
amber("엠버","amber");
final String korean;
final String english;
const NewColor(this.korean, this.english);
}
print(NewColor.amber.korean);
print(NewColor.amber.english);
import 'dart:ui';
import 'package:blog_app/model/todo.dart';
import 'package:blog_app/widget/filter_bottom_sheet.dart';
import 'package:blog_app/widget/todoTile.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
List<Todo> todos = [];
readData() async {
var dio = Dio();
var url = 'https://jsonplaceholder.typicode.com/todos';
var res = await dio.get(url);
if (res.statusCode == 200) {
var data = List<Map<String, dynamic>>.from(res.data);
setState(() => todos = data.map((e) => Todo.fromMap(e)).toList());
}
}
@override
void initState() {
super.initState();
readData();
}
TodoFilter selected = TodoFilter.all;
@override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
title: Text("Todo App"),
elevation: 0,
backgroundColor: Colors.transparent,
foregroundColor: Colors.black,
flexibleSpace: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(),
),
),
actions: [
IconButton(
onPressed: () {
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) => FilterBottomSheet(
filter: selected,
onApply: (value) {
setState(() => selected = value);
}));
},
icon: Icon(Icons.wifi)),
IconButton(
onPressed: () {
readData();
},
icon: Icon(Icons.refresh))
],
),
body: ListView.builder(
itemCount: todos.length,
itemBuilder: (context, index) =>
TodoTile(todo: filterMaker(todos)[index]),
));
}
List<Todo> filterMaker(List<Todo> value) {
switch (selected) {
case TodoFilter.all:
return value;
case TodoFilter.completed:
return value.where((element) => element.completed == true).toList();
case TodoFilter.incompleted:
return value.where((element) => element.completed == false).toList();
}
}
}
main.dart
main_page.dart
todo.dart
todoTile.dart
filter_bottom_sheet.dart