mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
RepoSelector: Show the datetime in relative terms
Unless it is more than 30 days
This commit is contained in:
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:function_types/function_types.dart';
|
import 'package:function_types/function_types.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
//import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:timeago/timeago.dart' as timeago;
|
||||||
|
|
||||||
import 'package:gitjournal/analytics.dart';
|
import 'package:gitjournal/analytics.dart';
|
||||||
import 'package:gitjournal/apis/githost_factory.dart';
|
import 'package:gitjournal/apis/githost_factory.dart';
|
||||||
@ -13,6 +13,8 @@ import 'package:gitjournal/setup/error.dart';
|
|||||||
import 'package:gitjournal/setup/loading.dart';
|
import 'package:gitjournal/setup/loading.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
|
//import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
|
||||||
class GitHostSetupRepoSelector extends StatefulWidget {
|
class GitHostSetupRepoSelector extends StatefulWidget {
|
||||||
final GitHost gitHost;
|
final GitHost gitHost;
|
||||||
final Func1<GitHostRepo, void> onDone;
|
final Func1<GitHostRepo, void> onDone;
|
||||||
@ -229,16 +231,8 @@ class _RepoTile extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var theme = Theme.of(context);
|
var theme = Theme.of(context);
|
||||||
final _dateFormat = DateFormat('dd MMM, yyyy');
|
|
||||||
var textTheme = theme.textTheme;
|
var textTheme = theme.textTheme;
|
||||||
|
|
||||||
Widget trailing = Container();
|
|
||||||
if (repo.updatedAt != null) {
|
|
||||||
var dateStr = _dateFormat.format(repo.updatedAt);
|
|
||||||
|
|
||||||
trailing = Text(dateStr, style: textTheme.caption);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var iconsRow = Row(
|
var iconsRow = Row(
|
||||||
children: [
|
children: [
|
||||||
@ -277,7 +271,7 @@ class _RepoTile extends StatelessWidget {
|
|||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(repo.fullName),
|
title: Text(repo.fullName),
|
||||||
trailing: trailing,
|
trailing: _SmartDateTime(repo.updatedAt, textTheme.caption),
|
||||||
selected: selected,
|
selected: selected,
|
||||||
contentPadding: const EdgeInsets.all(0.0),
|
contentPadding: const EdgeInsets.all(0.0),
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
@ -311,3 +305,35 @@ class _IconText extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class _SmartDateTime extends StatelessWidget {
|
||||||
|
final DateTime dt;
|
||||||
|
final TextStyle style;
|
||||||
|
|
||||||
|
_SmartDateTime(this.dt, this.style);
|
||||||
|
|
||||||
|
static final _dateFormat = DateFormat('d MMM yyyy');
|
||||||
|
static final _dateFormatWithoutYear = DateFormat('d MMM');
|
||||||
|
static final thirtyDaysAgo =
|
||||||
|
DateTime.now().subtract(const Duration(days: 30));
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (dt == null) {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
|
||||||
|
String text;
|
||||||
|
|
||||||
|
if (dt.isAfter(thirtyDaysAgo)) {
|
||||||
|
Locale locale = Localizations.localeOf(context);
|
||||||
|
text = timeago.format(dt, locale: locale.languageCode);
|
||||||
|
} else if (dt.year == DateTime.now().year) {
|
||||||
|
text = _dateFormatWithoutYear.format(dt);
|
||||||
|
} else {
|
||||||
|
text = _dateFormat.format(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Text(text, style: style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -910,6 +910,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.10"
|
version: "0.3.10"
|
||||||
|
timeago:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: timeago
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.27"
|
||||||
tool_base:
|
tool_base:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -56,6 +56,7 @@ dependencies:
|
|||||||
receive_sharing_intent: ^1.4.0+2
|
receive_sharing_intent: ^1.4.0+2
|
||||||
in_app_purchase: ^0.3.4+5
|
in_app_purchase: ^0.3.4+5
|
||||||
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
||||||
|
timeago: ^2.0.27
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user