-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* design empty message screen * merge main in current branch * message thread screen * show relative date * code refactoring * fix list ui * rename message to thread list * Chat screen (#30) * design chat screen * create separate service file for message * fix title * fix showing same sender name && make perfection loading in UI * fix showing user name when time change for same sender in group thread * manage padding for showing date header * localise string * manage send button color mode * change typo userNameFirstLetter -> firstChar
- Loading branch information
1 parent
f0f696a
commit e99a693
Showing
33 changed files
with
4,149 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:style/extenstions/date_extenstions.dart'; | ||
import 'package:yourspace_flutter/domain/extenstions/context_extenstions.dart'; | ||
|
||
enum DateFormatType { | ||
w, | ||
weekShort, | ||
month, | ||
relativeMonth, | ||
dayMonth, | ||
dayMonthFull, | ||
monthYear, | ||
monthDayYear, | ||
dayMonthYear, | ||
year, | ||
time, | ||
pastTime, | ||
relativeTime, | ||
relativeDate, | ||
relativeDateWeekday, | ||
serverIso | ||
} | ||
|
||
enum DateRangeFormatType { | ||
monthYear, | ||
relativeDate, | ||
dayMonthYear, | ||
} | ||
|
||
extension DateFormatter on DateTime { | ||
String format(BuildContext context, DateFormatType type) { | ||
if (isUtc) return toLocal().format(context, type); | ||
|
||
switch (type) { | ||
case DateFormatType.w: | ||
return DateFormat('E').format(this).substring(0, 1); | ||
case DateFormatType.weekShort: | ||
return DateFormat('EEE').format(this); | ||
case DateFormatType.month: | ||
return DateFormat('MMMM').format(this); | ||
case DateFormatType.relativeMonth: | ||
return year == DateTime.now().year | ||
? format(context, DateFormatType.month) | ||
: format(context, DateFormatType.monthYear); | ||
case DateFormatType.dayMonth: | ||
return DateFormat('dd MMM').format(this); | ||
case DateFormatType.dayMonthFull: | ||
return DateFormat('dd MMMM').format(this); | ||
case DateFormatType.monthYear: | ||
return DateFormat('MMMM yyyy').format(this); | ||
case DateFormatType.monthDayYear: | ||
return DateFormat('MMM dd, yyyy').format(this); | ||
case DateFormatType.dayMonthYear: | ||
return DateFormat('dd MMM yyyy').format(this); | ||
case DateFormatType.year: | ||
return DateFormat('yyyy').format(this); | ||
case DateFormatType.time: | ||
final is24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat; | ||
return DateFormat(is24HourFormat ? 'HH:mm' : 'hh:mm a') | ||
.format(toLocal()); | ||
case DateFormatType.relativeTime: | ||
return _relativeTime(context); | ||
case DateFormatType.relativeDate: | ||
return _relativeDate(context, false); | ||
case DateFormatType.relativeDateWeekday: | ||
return _relativeDate(context, true); | ||
case DateFormatType.pastTime: | ||
return _formattedPastTime(context); | ||
case DateFormatType.serverIso: | ||
return DateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(toUtc()); | ||
} | ||
} | ||
|
||
int get secondsSinceEpoch => millisecondsSinceEpoch ~/ 1000; | ||
|
||
static String formatDateRange({ | ||
required BuildContext context, | ||
required DateTime startDate, | ||
required DateTime endDate, | ||
DateRangeFormatType formatType = DateRangeFormatType.relativeDate, | ||
}) { | ||
if (startDate.startOfDay.isAtSameMomentAs(endDate.startOfDay)) { | ||
if (DateRangeFormatType.relativeDate == formatType) { | ||
return startDate.format(context, DateFormatType.relativeDate); | ||
} else if (DateRangeFormatType.monthYear == formatType) { | ||
return startDate.format(context, DateFormatType.monthYear); | ||
} else { | ||
return startDate.format(context, DateFormatType.dayMonthYear); | ||
} | ||
} else { | ||
if (DateRangeFormatType.relativeDate == formatType) { | ||
return '${startDate.format(context, DateFormatType.relativeDate)} - ${endDate.format(context, DateFormatType.relativeDate)}'; | ||
} else if (DateRangeFormatType.monthYear == formatType) { | ||
return '${startDate.format(context, DateFormatType.monthYear)} - ${endDate.format(context, DateFormatType.monthYear)}'; | ||
} else { | ||
if (startDate.year == endDate.year) { | ||
return '${startDate.format(context, DateFormatType.dayMonth)} - ${endDate.format(context, DateFormatType.dayMonthYear)}'; | ||
} else { | ||
return '${startDate.format(context, DateFormatType.dayMonthYear)} - ${endDate.format(context, DateFormatType.dayMonthYear)}'; | ||
} | ||
} | ||
} | ||
} | ||
|
||
String _relativeDate(BuildContext context, bool includeWeekday) { | ||
final today = DateTime.now(); | ||
final yesterday = today.add(const Duration(days: -1)); | ||
|
||
if (isSameDay(today)) { | ||
return context.l10n.common_today; | ||
} else if (isSameDay(yesterday)) { | ||
return context.l10n.common_yesterday; | ||
} else if (year == today.year) { | ||
return DateFormat('${includeWeekday ? 'EEEE, ' : ''}d MMMM').format(this); | ||
} else { | ||
return DateFormat('${includeWeekday ? 'EEEE, ' : ''}d MMM yyyy') | ||
.format(this); | ||
} | ||
} | ||
|
||
String _formattedPastTime(BuildContext context) { | ||
final DateTime currentTime = DateTime.now(); | ||
|
||
if (isToday) { | ||
final int dateSeconds = millisecondsSinceEpoch ~/ 1000; | ||
final int currentTimeSeconds = currentTime.millisecondsSinceEpoch ~/ 1000; | ||
|
||
if ((currentTimeSeconds - dateSeconds) < 60) { | ||
return context.l10n.common_just_now; | ||
} else if ((currentTimeSeconds - dateSeconds) < (60 * 60)) { | ||
final int minutesAgo = (currentTimeSeconds - dateSeconds) ~/ 60; | ||
return '$minutesAgo ${context.l10n.common_min_ago}'; | ||
} else { | ||
final int hoursAgo = (currentTimeSeconds - dateSeconds) ~/ (60 * 60); | ||
|
||
if (hoursAgo < 2) { | ||
return '$hoursAgo ${context.l10n.common_hour_ago}'; | ||
} else { | ||
return '$hoursAgo ${context.l10n.common_hours_ago}'; | ||
} | ||
} | ||
} else if (isYesterday) { | ||
return context.l10n.common_yesterday; | ||
} else { | ||
final bool isSameYear = year == currentTime.year; | ||
|
||
final String format = | ||
isSameYear ? 'dd MMM' : 'dd MMM yyyy'; | ||
return DateFormat(format).format(this); | ||
} | ||
} | ||
|
||
String _relativeTime(BuildContext context) { | ||
final time = format(context, DateFormatType.time); | ||
|
||
final today = DateTime.now(); | ||
final yesterday = today.add(const Duration(days: -1)); | ||
|
||
final String day; | ||
if (isSameDay(today)) { | ||
day = 'Today'; | ||
} else if (isSameDay(yesterday)) { | ||
day = 'Yesterday'; | ||
} else if (year == today.year) { | ||
day = DateFormat('d MMM').format(this); | ||
} else { | ||
day = DateFormat('d MMM yyyy').format(this); | ||
} | ||
return '$day, $time'; | ||
} | ||
|
||
bool get isToday => startOfDay.isAtSameMomentAs(DateTime.now().startOfDay); | ||
|
||
bool get isYesterday => startOfDay.isAtSameMomentAs( | ||
DateTime.now().startOfDay.subtract(const Duration(days: 1)), | ||
); | ||
} | ||
|
||
extension StringDateFormatter on String { | ||
String convertTo12HrTime() => DateFormat("hh:mm a") | ||
.format(DateFormat("HH:mm").parse(this)) | ||
.toLowerCase(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:style/extenstions/context_extenstions.dart'; | ||
import 'package:style/indicator/progress_indicator.dart'; | ||
import 'package:style/text/app_text_dart.dart'; | ||
|
||
class ProfileImage extends StatefulWidget { | ||
final double size; | ||
final String profileImageUrl; | ||
final String firstLetter; | ||
final TextStyle? style; | ||
final Color? backgroundColor; | ||
|
||
const ProfileImage({ | ||
super.key, | ||
this.size = 64, | ||
required this.profileImageUrl, | ||
required this.firstLetter, | ||
this.style, | ||
this.backgroundColor, | ||
}); | ||
|
||
@override | ||
State<ProfileImage> createState() => _ProfileImageState(); | ||
} | ||
|
||
class _ProfileImageState extends State<ProfileImage> { | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
width: widget.size, | ||
height: widget.size, | ||
child: ClipRRect( | ||
borderRadius: BorderRadius.circular(widget.size / 2), | ||
child: widget.profileImageUrl.isNotEmpty | ||
? CachedNetworkImage( | ||
imageUrl: widget.profileImageUrl, | ||
placeholder: (context, url) => const AppProgressIndicator( | ||
size: AppProgressIndicatorSize.small), | ||
errorWidget: (context, url, error) => const Icon(Icons.error), | ||
fit: BoxFit.cover, | ||
) | ||
: Container( | ||
color: widget.backgroundColor ?? context.colorScheme.containerInverseHigh, | ||
child: Center( | ||
child: Text( | ||
widget.firstLetter, | ||
style: widget.style ?? AppTextStyle.subtitle2 | ||
.copyWith(color: context.colorScheme.textPrimary)), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.