dart coompare date code example
Example 1: how to show date only in flutter
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Current Date Example',
home: DateExample(),
);
}
}
class DateExample extends StatelessWidget {
const DateExample({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text(DateFormat("yyyy-MM-dd").format(DateTime.now()))),
);
}
}
Example 2: compare date month and year in datetime in flutter
Since I asked this, extension methods have been released in Dart. I would now
implement option 1 as an extension method:
extension DateOnlyCompare on DateTime {
bool isSameDate(DateTime other) {
return this.year == other.year && this.month == other.month
&& this.day == other.day;
}
}
About Extensions :
https://dart.dev/guides/language/extension-methods