我需要在我的应用中存储和比较日期(无时间),而无需关心时区。
我可以看到三种解决方案:
(date1.year == date2.year && date1.month == date2.month && date1.day == date2.day)
这就是我现在正在做的事情,但是太冗长了。
date1.format("YYYYMMDD") == date2.format("YYYYMMDD")
这仍然很冗长(尽管还不算太糟),但对我来说似乎效率不高...
自己创建一个新的Date类,也许将日期存储为“ YYYYMMDD”字符串或自1980年1月1日以来的天数。但这意味着重新实现一堆复杂的逻辑,例如不同的月长,加/减和/年。
创建新类也避免了我担心的极端情况,Duration(days: 1)由于夏令时的更改,添加结果的日期相同。但是我可能没有想到这种方法的一些极端情况...
这些解决方案中哪一个最好,还是我没有想到的更好的解决方案?
我有一个简单的 CustomPaint/CustomPainter 可以绘制一段圆(下面的代码)。我读过我不能使用 GestureDetector 因为它不是一个合适的小部件,那么获取输入的最佳方式是什么?
我将有一堆片段放在一起,所以我需要像素精确的触摸位置。
我想到了两种可能:
我的自定义画家:
class _SegmentPainter extends CustomPainter {
static const offset = -pi/2;
double start;
double end;
double innerRadius;
double outerRadius;
Color color;
_SegmentPainter(this.start, this.end, {this.innerRadius = 0.0, this.outerRadius, this.color});
@override bool shouldRepaint(CustomPainter oldDelegate) => this == oldDelegate;
@override bool shouldRebuildSemantics(CustomPainter oldDelegate) => this == oldDelegate;
@override
void paint(Canvas canvas, Size size) {
Path path = new Path();
path.arcTo(Rect.fromCircle(center: new Offset(0.0, 0.0), radius: outerRadius), offset + start, end-start, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的 MaterialApp 主题中的 AppBarTheme 在我的应用程序中的任何地方实现透明的应用程序栏。但这导致文本大小成为默认值 14.0 而不是标题大小。
我想这与 TextStyle 继承有关,但我对此知之甚少。
示例代码:
class ExampleScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
ThemeData theme = ThemeData();
return MaterialApp(
theme: theme.copyWith(
appBarTheme: AppBarTheme(
color: Colors.transparent,
brightness: Brightness.light,
elevation: 0,
//I want the defaults, which is why I'm copying an 'empty' ThemeData
//perhaps there's a better way to do this?
textTheme: theme.textTheme,
iconTheme: theme.iconTheme,
),
),
home: Scaffold(
appBar: AppBar(
title: Text('AppBar!'),
),
body: Text('Some text'),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)