首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在使用颤振表日历生成页时立即导入数据

如何在使用颤振表日历生成页时立即导入数据
EN

Stack Overflow用户
提问于 2020-11-23 05:44:37
回答 1查看 310关注 0票数 0

目前,我正在使用带有颤振的表日历制作一个ToDo应用程序。

操作是在单击表日历的日期时导入当天的ToDo列表。

它检索日历表上选定日期的待办事项列表。

但是,问题是,当您第一次输入totoList页面时,必须单击日期,以便接收该日期的totoList。

因此,我想知道如何在访问todoList页面时立即获得当天的TODO列表,而不必选择特定的日期。

代码语言:javascript
运行
复制
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:take_a_note_project/model/todo_model.dart';
import 'package:take_a_note_project/todoList/header.dart';
import 'package:take_a_note_project/todoList/todoList_handler.dart';

class TodoList extends StatefulWidget {
    @override
    _TodoListState createState() => _TodoListState();
}

class _TodoListState extends State<TodoList> {
    Header header;
    TodoModel todoModel;
    CalendarController controller;
    TodoListHandler todoListHandler;
    static TextEditingController eventController;

    @override
    void initState() {
        super.initState();
        header = Header();
        controller = CalendarController();
        eventController = TextEditingController();
    }

    @override
    void dispose() {
        controller.dispose();
        super.dispose();
    }

    @override
    Widget build(BuildContext context) {
        todoListHandler = Provider.of<TodoListHandler>(context);
        return Scaffold(
                backgroundColor: Color(0xffFEE8D6),
                body: SafeArea(
                child: SingleChildScrollView(
                child: Column(
                children: <Widget>[
        _TableCalendar(),
                SingleChildScrollView(
                        physics: ScrollPhysics(),
                child: Column(
                children: [
        _OnProgressBox(),
                _DoneBox()
                                        ]
                                    ),
                                  ),
                                ],
                              )
                          )
                      ),
        floatingActionButton: FloatingActionButton(
                child: Icon(Icons.create),
                onPressed: _showAddDialog,
                      ),
                    );
    }

    Widget _OnProgressBox() {
        return Stack(
                children: <Widget>[
        Card(
                margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
        color: Color(0xffFFF8DC),
                child: Column(
                children: <Widget>[
        SizedBox(height: 50,),
        ListView.builder(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemCount: todoListHandler.onProgressTodo.length,
                itemBuilder: (context, index) {
            return GestureDetector(
                    child: todoCard(
                    context, todoListHandler.onProgressTodo, index),
                    onTap: () {
                todoListHandler.onProgressTodo[index].isDone = 1;
                todoListHandler.setTodo(
                        todoListHandler.onProgressTodo[index]);
                todoListHandler.relodeTodos(controller.selectedDay);
            },
                                      );
        }
                                ),
        SizedBox(height: 20,)
                              ],
                            ),
                          ),
        Header.getCardHeader(
                context: context, text: "TO DO", customColor: Color(0xffca3e47)),
                        ]
                    );
    }

    Widget _DoneBox() {
        return Stack(
                children: <Widget>[
        Card(
                margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
        color: Colors.grey,
                child: Column(
                children: <Widget>[
        SizedBox(height: 50,),
        ListView.builder(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                itemCount: todoListHandler.doneTodo.length,
                itemBuilder: (context, index) {
            return GestureDetector(
                    child: todoCard(
                    context, todoListHandler.doneTodo, index),
                    onTap: () {
                todoListHandler.doneTodo[index].isDone = 0;
                todoListHandler.setTodo(todoListHandler.doneTodo[index]);
                todoListHandler.relodeTodos(controller.selectedDay);
            },
                                      );
        }
                                ),
        SizedBox(height: 20,)
                              ],
                            ),
                          ),
        Header.getCardHeader(
                context: context, text: "DONE", customColor: Color(0xff34465d)),
                        ]
                    );
    }

    Widget _TableCalendar() {
        return TableCalendar( // Calendar Style
                initialCalendarFormat: CalendarFormat.week,
                events: todoListHandler.events,
                calendarStyle: CalendarStyle(
                // Calendar Style
                todayColor: Colors.orange,
                selectedColor: Theme
                .of(context)
                .primaryColor,
                todayStyle: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 18.0,
                color: Colors.white,
                        ),
                      ),
        headerStyle: HeaderStyle(
                centerHeaderTitle: true,
                formatButtonDecoration: BoxDecoration(
                color: Colors.orange,
                borderRadius: BorderRadius.circular(20.0)
                        ),
        formatButtonTextStyle: TextStyle(color: Colors.white),
                      ),
        calendarController: controller,
                onDaySelected: (date, events, holidays) {
            setState(() {
                print(events);
                todoListHandler.selectedEvents = events;
                todoListHandler.relodeTodos(controller.selectedDay);
            });
        },
        builders: CalendarBuilders(
                selectedDayBuilder: (context, date, events) =>
        Container(
                child: Text(
                date.day.toString(), style: TextStyle(color: Colors.white),),
        margin: const EdgeInsets.all(4.0),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                color: Theme
                .of(context)
                .primaryColor,
                borderRadius: BorderRadius.circular(10.0),
                              ),
                            ),
        todayDayBuilder: (context, date, events) =>
        Container(
                child: Text(
                date.day.toString(), style: TextStyle(color: Colors.white),),
        margin: const EdgeInsets.all(4.0),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                color: Colors.orange,
                borderRadius: BorderRadius.circular(10.0)
                              ),
                            ),
                      ),
                    );
    }

    _showAddDialog() {
        showDialog(
                context: context,
                builder: (context) =>
        AlertDialog(
                title: Text(
                "할 일을 추가합니다.", style: TextStyle(fontWeight: FontWeight.bold)),
        elevation: 24.0,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(20.0))
                              ),
        content: TextField(
                controller: eventController,
                              ),
        actions: <Widget>[
        SizedBox(
                width: MediaQuery.of(context).size.width,
                child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
        RaisedButton(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.lightBlue)
                                        ),
        child: Text("Save", style: TextStyle(
                fontWeight: FontWeight.bold, color: Colors.lightBlue),),
        onPressed: () {
            todoListHandler.addTodoList(
                    controller.selectedDay, eventController);
            Navigator.pop(context);
        },
                                      )
                                    ],
                                  ),
                                )
                              ],
                            )
                    );
    }

    changeList(todoItem) {
        showDialog(
                context: context,
                builder: (context) =>
        AlertDialog(
                title: Text(
                "할 일을 수정합니다.", style: TextStyle(fontWeight: FontWeight.bold),),
        shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(20.0))
                              ),
        content: TextField(controller: eventController),
        actions: <Widget>[
        SizedBox(
                width: MediaQuery.of(context).size.width,
                child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
        RaisedButton(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.lightBlue)
                                          ),
        child: Text("Save", style: TextStyle(
                fontWeight: FontWeight.bold, color: Colors.lightBlue),),
        onPressed: () {
            todoItem.todo = eventController.text;
            todoListHandler.setTodo(todoItem);
            todoListHandler.relodeTodos(controller.selectedDay);
            eventController.clear();
            Navigator.pop(context);
        }
                                      ),
        SizedBox(width: 10.0),
        RaisedButton(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.deepOrangeAccent)
                                        ),
        child: Text("Cancel", style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.deepOrangeAccent),),
        onPressed: () {
            Navigator.pop(context);
        },
                                      )
                                    ],
                                  ),
                                )
                              ],
                            )
                    );
    }

    deleteList(todoItem) {
        showDialog(
                context: context,
                builder: (context) =>
        AlertDialog(
                title: Center(
                child: Text(
                "정말 삭제하시겠어요?", style: TextStyle(fontWeight: FontWeight.bold),),
                              ),
        shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(20.0))
                              ),
        actions: <Widget>[
        SizedBox(
                width: MediaQuery.of(context).size.width,
                child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
        RaisedButton(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.lightBlue)
                                          ),
        child: Text("Yes", style: TextStyle(
                fontWeight: FontWeight.bold, color: Colors.lightBlue),),
        onPressed: () {
            todoListHandler.deleteTodo(todoItem.key);
            todoListHandler.relodeTodos(controller.selectedDay);
            Navigator.pop(context);
        }
                                      ),
        SizedBox(width: 10.0),
        RaisedButton(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(18.0),
                side: BorderSide(color: Colors.deepOrangeAccent)
                                        ),
        child: Text("Cancel", style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.deepOrangeAccent),),
        onPressed: () {
            Navigator.pop(context);
        },
                                      )
                                    ],
                                  ),
                                )
                              ],
                            )
                    );
    }

    Widget todoCard(BuildContext context, todoItem, int index) {
        Icon leading;
        Color color;
        Color titleColor;
        int isDone = todoItem[index].isDone;
        String toDo = todoItem[index].todo;

        if (isDone == 1) {
            color = Colors.white38;
            leading = Icon(Icons.check_circle, color: Colors.white);
            titleColor = Colors.white;
        } else {
            color = Color(0xffEEE8CD);
            leading = Icon(Icons.radio_button_unchecked, color: Colors.black38,);
            titleColor = Colors.black;
        }

        return Card(
                elevation: 5,
                color: color,
                child: ListTile(
                leading: leading,
                title: Text(toDo, style: TextStyle(
                fontWeight: FontWeight.normal, fontSize: 20, color: titleColor)),
        trailing: IconButton(
                icon: Icon(Icons.more_vert),
                onPressed: () {
            settingBox(context, todoItem[index]);
        },
                          ),
                        )
                    );
    }

    Widget updateTodo(BuildContext context, todoItem) {
        return ListTile(
                leading: Icon(Icons.edit),
                title: Text("To Do 수정"),
                onTap: () {
            Navigator.pop(context);
            changeList(todoItem);
        },
                    );
    }

    Widget deleteTodo(BuildContext context, todoItem) {
        return ListTile(
                leading: Icon(Icons.delete_forever),
                title: Text("To Do 삭제"),
                onTap: () {
            Navigator.pop(context);
            deleteList(todoItem);
        },
                    );
    }

    settingBox(BuildContext context, todoItem) {
        showBottomSheet(
                context: context,
                builder: (context) {
        return Container(
                color: Color(0xFF737373),
                height: 115,
                child: Container(
                decoration: BoxDecoration(
                color: Theme
                .of(context)
                .canvasColor,
                borderRadius: BorderRadius.only(
                topLeft: const Radius.circular(10),
                topRight: const Radius.circular(10),
                                    )),
        child: Column(
                children: [
        updateTodo(context, todoItem),
                deleteTodo(context, todoItem)
                                  ],
                                ),
                              ),
                          );
                        }
                    );
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-23 07:43:37

你在找这样的东西吗?

代码语言:javascript
运行
复制
onCalendarCreated: (DateTime first, DateTime last, CalendarFormat format) {
  selectDay(DateTime.now());
},
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64963121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档