Skip to content

Instantly share code, notes, and snippets.

View DineshKachhot's full-sized avatar
🎯
Focusing

Dinesh Kachhot DineshKachhot

🎯
Focusing
View GitHub Profile
@DineshKachhot
DineshKachhot / time_ago_since_now.dart
Created March 1, 2019 06:08
Flutter Time ago calculator
static String timeAgoSinceDate(String dateString, {bool numericDates = true}) {
DateTime date = DateTime.parse(dateString);
final date2 = DateTime.now();
final difference = date2.difference(date);
if ((difference.inDays / 365).floor() >= 2) {
return '${(difference.inDays / 365).floor()} years ago';
} else if ((difference.inDays / 365).floor() >= 1) {
return (numericDates) ? '1 year ago' : 'Last year';
} else if ((difference.inDays / 30).floor() >= 2) {
@DineshKachhot
DineshKachhot / template.dart
Created August 30, 2018 06:20 — forked from nkraev/template.dart
This gist shows the GestureDetector usage on latest dart 2 preview version
import 'package:flutter/material.dart';
class SignaturePainter extends CustomPainter {
SignaturePainter(this.points);
final List<Offset> points;
void paint(Canvas canvas, Size size) {
Paint paint = new Paint()
..color = Colors.black
@DineshKachhot
DineshKachhot / Array+FilterUniqueByKey.swift
Created July 12, 2018 05:14
Array extension to return the unique list of objects based on a given key.
extension Array {
func unique<T:Hashable>(by: ((Element) -> (T))) -> [Element] {
var set = Set<T>() //Keep unique list in a Set for fast retrieval
var orderedArray = [Element]() //Keeping the unique list of elements but ordered
for value in self {
if !set.contains(by(value)) {
set.insert(by(value))
orderedArray.append(value)
}
}