calendar - 有人可以用框架或其他东西帮助我在 flutter 中实现这种类型的日历小部件吗

标签 calendar flutter

from the design

我想显示日历而不是对话框。我希望能够像屏幕截图中那样选择日期间隔。

最佳答案

我建议您不要重新发明轮子并选择一个社区日历小部件(如 that one ),但如果您需要自定义解决方案,您可以从非常简单的事情开始。例如,如果您需要选择一个范围,您可能只需要一个网格和几个这样的按钮:

import 'package:flutter/material.dart';

class CalendarPage extends StatefulWidget {
  final String title;

  CalendarPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _CalendarPageState();
}

class _CalendarPageState extends State<CalendarPage> {
  int _left = -1;
  int _right = -1;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: GridView.count(
        crossAxisCount: 7,
        children: List.generate(31, (index) {
          return Container(
              decoration: BoxDecoration(
                border: Border.all(width: 2.0, color: Colors.black38),
                color: _isInBounds(index)
                    ? Colors.yellow[100]
                    : Colors.transparent,
                borderRadius: const BorderRadius.all(const Radius.circular(8.0)),
              ),
              margin: const EdgeInsets.all(2.0),
              child: FlatButton(
                onPressed: () => _handleTap(index),
                child: Text('${index + 1}',
                    style: Theme.of(context).textTheme.body2,
                    textAlign: TextAlign.center)));
        }),
       ));
  }

  void _handleTap(index) {
    setState(() {
      if (_left == -1)
        _left = index;
      else if (_right == -1) _right = index;
    });
  }

  bool _isInBounds(int index) => _left <= index && index <= _right;
}

关于calendar - 有人可以用框架或其他东西帮助我在 flutter 中实现这种类型的日历小部件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52496035/

相关文章:

Java 检查数字月份

android - 以编程方式将日历事件添加到 iOS 或 Android 上的 Outlook

html - Flutter,从网站获取特定图像

dart - Flutter 下拉按钮绑定(bind)键值数组

ios - 具有 iOS 年度 View 的日历控件

python DST 和 GMT 管理到调度程序中

firebase - 如何在Flutter中使用.currentUser方法

android - 为什么我将 Razorpay 与 Flutter 结合使用会出现此错误 => Uncaught TypeError :window. getDeviceDetails is not a function and BAD_REQUEST_ERROR?

java - Java中如何比较时间戳是否在给定时间段的范围内

flutter - 如何在 flutter 中使用 BLoC 模式添加回调?