<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Flutter 中可定制的時(shí)間規(guī)劃器

          共 16362字,需瀏覽 33分鐘

           ·

          2021-08-12 00:05

          ?

          「老孟導(dǎo)讀」:今天發(fā)現(xiàn)一個(gè)特別好的插件-時(shí)間規(guī)劃器,這個(gè)插件里面有很多我們可以學(xué)習(xí)的知識(shí)點(diǎn),比如很多人問的表頭不動(dòng),內(nèi)容滑動(dòng),還有類似股票似的列表滑動(dòng)效果,這個(gè)插件都實(shí)現(xiàn)了,下面就看看這個(gè)插件吧。

          原文鏈接:https://medium.com/flutterdevs/explore-customizable-time-planner-in-flutter-c8108218b52c

          ?

          Flutter 從一開始就是一場(chǎng)偉大的邂逅。構(gòu)建引人入勝的 UI 從未如此快速。無論您是業(yè)余愛好者還是有教養(yǎng)的開發(fā)人員,都不難對(duì) Flutter 產(chǎn)生無可救藥的迷戀。所有軟件開發(fā)人員都明白日期是最棘手的事情。同樣,時(shí)間表也不是特例。

          在移動(dòng)應(yīng)用程序中,在很多情況下,用戶需要輸入出生日期、訂票、安排會(huì)議等日期。

          在在這個(gè)博客中,我們將**探索 Flutter 中可定制的時(shí)間規(guī)劃器。**我們還將在「Flutter」 應(yīng)用程序中使用「time_planner」包實(shí)現(xiàn)一個(gè)演示程序并創(chuàng)建一個(gè)可定制的時(shí)間規(guī)劃器。

          介紹

          一個(gè)令人愉快、易于使用且可自定義的時(shí)間規(guī)劃器,適用于 Flutter 移動(dòng)、桌面和 Web。這是一個(gè)小部件,用于按計(jì)劃向客戶顯示分配。每行顯示一個(gè)小時(shí),每列顯示一天,但您可以更改該部分的標(biāo)題并顯示您需要的任何其他內(nèi)容。

          此演示視頻展示了如何在 Flutter 中創(chuàng)建可自定義的時(shí)間規(guī)劃器。它展示了可定制的時(shí)間規(guī)劃器將如何在您的「Flutter」 應(yīng)用程序中使用「time_planner」包工作。它顯示當(dāng)用戶點(diǎn)擊任何行和列時(shí),將創(chuàng)建一個(gè)隨機(jī)時(shí)間規(guī)劃器。

          屬性

          時(shí)間規(guī)劃器的一些屬性是:

          • 「startHour」用來計(jì)時(shí)從這個(gè)開始,它會(huì)從1開始。
          • 「endHour」用來計(jì)時(shí)結(jié)束在這個(gè)時(shí)間,最大值為24。
          • 「headers」用于從這里創(chuàng)建日期,每一天都是一個(gè) TimePlannerTitle。您應(yīng)該至少創(chuàng)建一天。
          • 「tasks」用于列出時(shí)間規(guī)劃器上的小部件。
          • 「style」用于時(shí)間規(guī)劃器的Style。
          • 「currentTimeAnimation」用于小部件加載滾動(dòng)到帶有動(dòng)畫的當(dāng)前時(shí)間。默認(rèn)為真。

          使用

          1. 添加依賴

            time_planner: ^0.0.3
          2. 導(dǎo)入

            import 'package:time_planner/time_planner.dart';
          3. 執(zhí)行 「flutter packages get」 命令

          創(chuàng)建一個(gè) 「main.dart」 文件,創(chuàng)建一個(gè) 「TimePlannerTask」 集合,

          List<TimePlannerTask> tasks = [];

          創(chuàng)建 「_addObject」方法,方法內(nèi)添加顏色并添加 「setState」 方法,在 「setState」 方法內(nèi),給集合 tasks 添加 「TimePlannerTask」 組件,在這個(gè)組件中,添加顏色、日期時(shí)間、minutesDuration 和 daysDuration。當(dāng)用戶點(diǎn)擊時(shí)間規(guī)劃器時(shí),我們還將顯示snackBar消息。

          void _addObject(BuildContext context) {
            List<Color?> colors = [
              Colors.purple,
              Colors.blue,
              Colors.green,
              Colors.orange,
              Colors.cyan
            ];

            setState(() {
              tasks.add(
                TimePlannerTask(
                  color: colors[Random().nextInt(colors.length)],
                  dateTime: TimePlannerDateTime(
                      day: Random().nextInt(10),
                      hour: Random().nextInt(14) + 6,
                      minutes: Random().nextInt(60)),
                  minutesDuration: Random().nextInt(90) + 30,
                  daysDuration: Random().nextInt(4) + 1,
                  onTap: () {
                    ScaffoldMessenger.of(context).showSnackBar(
                        SnackBar(content: Text('You click on time planner object')));
                  },
                  child: Text(
                    'this is a demo',
                    style: TextStyle(color: Colors.grey[350], fontSize: 12),
                  ),
                ),
              );
            });

            ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('Random task added to time planner!')));
          }

          下面我們將添加 「TimePlanner」 組件,設(shè)置其 startHour, endHour, 和 headers,然后添加 「TimePlannerTitle」 組件,

          TimePlanner(
            startHour: 2,
            endHour: 24,
            headers: [
              TimePlannerTitle(
                date: "7/20/2021",
                title: "tuesday",
              ),
              TimePlannerTitle(
                date: "7/21/2021",
                title: "wednesday",
              ),
              TimePlannerTitle(
                date: "7/22/2021",
                title: "thursday",
              ),
              TimePlannerTitle(
                date: "7/23/2021",
                title: "friday",
              ),
              TimePlannerTitle(
                date: "7/24/2021",
                title: "saturday",
              ),
              TimePlannerTitle(
                date: "7/25/2021",
                title: "sunday",
              ),
              TimePlannerTitle(
                date: "7/26/2021",
                title: "monday",
              ),
              TimePlannerTitle(
                date: "7/27/2021",
                title: "tuesday",
              ),
              TimePlannerTitle(
                date: "7/28/2021",
                title: "wednesday",
              ),
              TimePlannerTitle(
                date: "7/29/2021",
                title: "thursday",
              ),
              TimePlannerTitle(
                date: "7/30/2021",
                title: "friday",
              ),
              TimePlannerTitle(
                date: "7/31/2021",
                title: "Saturday",
              ),
            ],
            tasks: tasks,
            style: TimePlannerStyle(
                showScrollBar: true
            ),
          ),

          我們接下來創(chuàng)建 「FloatingActionButton」 按鈕,

          floatingActionButton: FloatingActionButton(
            onPressed: () => _addObject(context),
            tooltip: 'Add random task',
            child: Icon(Icons.add),
          ),

          運(yùn)行,效果如下:


          完整代碼

          import 'dart:math';

          import 'package:flutter/material.dart';
          import 'package:flutter_customizable_time_plan/splash_screen.dart';
          import 'package:time_planner/time_planner.dart';

          void main() {
            runApp(MyApp());
          }

          class MyApp extends StatelessWidget {
            @override
            Widget build(BuildContext context) {
              return MaterialApp(
                debugShowCheckedModeBanner: false,
                theme: ThemeData.dark(),
                home: Splash()
              );
            }
          }

          class MyHomePage extends StatefulWidget {
            MyHomePage({Key? key, required this.title}) : super(key: key);

            final String title;

            @override
            _MyHomePageState createState() => _MyHomePageState();
          }

          class _MyHomePageState extends State<MyHomePage{
            List<TimePlannerTask> tasks = [];

            void _addObject(BuildContext context) {
              List<Color?> colors = [
                Colors.purple,
                Colors.blue,
                Colors.green,
                Colors.orange,
                Colors.cyan
              ];

              setState(() {
                tasks.add(
                  TimePlannerTask(
                    color: colors[Random().nextInt(colors.length)],
                    dateTime: TimePlannerDateTime(
                        day: Random().nextInt(10),
                        hour: Random().nextInt(14) + 6,
                        minutes: Random().nextInt(60)),
                    minutesDuration: Random().nextInt(90) + 30,
                    daysDuration: Random().nextInt(4) + 1,
                    onTap: () {
                      ScaffoldMessenger.of(context).showSnackBar(
                          SnackBar(content: Text('You click on time planner object')));
                    },
                    child: Text(
                      'this is a demo',
                      style: TextStyle(color: Colors.grey[350], fontSize: 12),
                    ),
                  ),
                );
              });

              ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: Text('Random task added to time planner!')));
            }

            @override
            Widget build(BuildContext context) {
              return Scaffold(
                appBar: AppBar(
                  automaticallyImplyLeading: false,
                  title: Text(widget.title),
                  centerTitle: true,
                ),
                body: Center(
                  child: TimePlanner(
                    startHour: 2,
                    endHour: 24,
                    headers: [
                      TimePlannerTitle(
                        date: "7/20/2021",
                        title: "tuesday",
                      ),
                      TimePlannerTitle(
                        date: "7/21/2021",
                        title: "wednesday",
                      ),
                      TimePlannerTitle(
                        date: "7/22/2021",
                        title: "thursday",
                      ),
                      TimePlannerTitle(
                        date: "7/23/2021",
                        title: "friday",
                      ),
                      TimePlannerTitle(
                        date: "7/24/2021",
                        title: "saturday",
                      ),
                      TimePlannerTitle(
                        date: "7/25/2021",
                        title: "sunday",
                      ),
                      TimePlannerTitle(
                        date: "7/26/2021",
                        title: "monday",
                      ),
                      TimePlannerTitle(
                        date: "7/27/2021",
                        title: "tuesday",
                      ),
                      TimePlannerTitle(
                        date: "7/28/2021",
                        title: "wednesday",
                      ),
                      TimePlannerTitle(
                        date: "7/29/2021",
                        title: "thursday",
                      ),
                      TimePlannerTitle(
                        date: "7/30/2021",
                        title: "friday",
                      ),
                      TimePlannerTitle(
                        date: "7/31/2021",
                        title: "Saturday",
                      ),
                    ],
                    tasks: tasks,
                    style: TimePlannerStyle(
                        showScrollBar: true
                    ),
                  ),
                ),
                floatingActionButton: FloatingActionButton(
                  onPressed: () => _addObject(context),
                  tooltip: 'Add random task',
                  child: Icon(Icons.add),
                ),
              );
            }
          }



          你可能還喜歡

          關(guān)注「老孟Flutter」
          讓你每天進(jìn)步一點(diǎn)點(diǎn)
          瀏覽 61
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日本a在线免费观看 | 97超碰人人草 | 天堂在线无码视频 | 五月天毛片 | 欧美xxxx操 |