Skip to content

Commit

Permalink
Merge branch 'mve3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
minikin authored Nov 26, 2024
2 parents 3bf0ccf + 96daec3 commit 01db066
Show file tree
Hide file tree
Showing 30 changed files with 1,277 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ abstract class DateFormatter {
/// - Yesterday
/// - 2 days ago
/// - Other cases: yMMMMd date format.
static String formatRecentDate(VoicesLocalizations l10n, DateTime dateTime) {
final now = DateTimeExt.now();
static String formatRecentDate(
VoicesLocalizations l10n,
DateTime dateTime, {
DateTime? from,
}) {
from ??= DateTimeExt.now();

final today = DateTime(now.year, now.month, now.day, 12);
final today = DateTime(from.year, from.month, from.day, 12);
if (dateTime.isSameDateAs(today)) return l10n.today;

final tomorrow = today.plusDays(1);
Expand All @@ -27,4 +31,23 @@ abstract class DateFormatter {

return DateFormat.yMMMMd().format(dateTime);
}

static String formatInDays(
VoicesLocalizations l10n,
DateTime dateTime, {
DateTime? from,
}) {
from ??= DateTimeExt.now();

final days = dateTime.isAfter(from) ? dateTime.difference(from).inDays : 0;

return l10n.inXDays(days);
}

static String formatShortMonth(
VoicesLocalizations l10n,
DateTime dateTime,
) {
return DateFormat.MMM().format(dateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class _UnlockPassword extends StatelessWidget {
Widget build(BuildContext context) {
return VoicesPasswordTextField(
controller: controller,
autofocus: true,
decoration: VoicesTextFieldDecoration(
labelText: context.l10n.unlockDialogHint,
errorText: error?.message(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/material.dart';

class GuidanceView extends StatefulWidget {
final List<Guidance> guidances;

const GuidanceView(this.guidances, {super.key});

@override
Expand All @@ -18,25 +19,6 @@ class _GuidanceViewState extends State<GuidanceView> {

GuidanceType? selectedType;

@override
void initState() {
super.initState();
filteredGuidances
..clear()
..addAll(widget.guidances);
}

@override
void didUpdateWidget(GuidanceView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.guidances != widget.guidances) {
filteredGuidances
..clear()
..addAll(widget.guidances);
_filterGuidances(selectedType);
}
}

@override
Widget build(BuildContext context) {
return Column(
Expand Down Expand Up @@ -74,6 +56,25 @@ class _GuidanceViewState extends State<GuidanceView> {
);
}

@override
void didUpdateWidget(GuidanceView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.guidances != widget.guidances) {
filteredGuidances
..clear()
..addAll(widget.guidances);
_filterGuidances(selectedType);
}
}

@override
void initState() {
super.initState();
filteredGuidances
..clear()
..addAll(widget.guidances);
}

void _filterGuidances(GuidanceType? type) {
selectedType = type;
filteredGuidances
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'package:catalyst_voices/widgets/images/voices_image_scheme.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_brands/catalyst_voices_brands.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';

class EmptyState extends StatelessWidget {
final String? title;
final String? description;
final Widget? image;
final Widget? imageBackground;

const EmptyState({
super.key,
this.title,
this.description,
this.image,
this.imageBackground,
});

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final textTheme = theme.textTheme;
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 64),
child: Column(
children: [
image ??
VoicesImagesScheme(
image: CatalystSvgPicture.asset(
VoicesAssets.images.noProposalForeground.path,
),
background: imageBackground ??
Container(
height: 180,
decoration: BoxDecoration(
color: theme.colors.onSurfaceNeutral08,
shape: BoxShape.circle,
),
),
),
const SizedBox(height: 24),
SizedBox(
width: 430,
child: Column(
children: [
Text(
_buildTitle(context),
style: textTheme.titleMedium
?.copyWith(color: theme.colors.textOnPrimaryLevel1),
),
const SizedBox(height: 8),
Text(
_buildDescription(context),
style: textTheme.bodyMedium
?.copyWith(color: theme.colors.textOnPrimaryLevel1),
textAlign: TextAlign.center,
),
],
),
),
],
),
),
);
}

String _buildDescription(BuildContext context) {
return description ?? context.l10n.noProposalStateDescription;
}

String _buildTitle(BuildContext context) {
return title ?? context.l10n.noProposalStateTitle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

class VoicesImagesScheme extends StatelessWidget {
final Widget image;
final Widget? background;

const VoicesImagesScheme({
super.key,
required this.image,
required this.background,
});

@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: [
if (background != null) background!,
image,
],
);
}
}
34 changes: 16 additions & 18 deletions catalyst_voices/apps/voices/lib/widgets/menu/voices_menu.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_view_models/catalyst_voices_view_models.dart';
import 'package:flutter/material.dart';

/// A menu of the app that
Expand Down Expand Up @@ -68,7 +69,7 @@ class _MenuButton extends StatelessWidget {

final textStyle = textTheme.bodyMedium?.copyWith(
color:
menuItem.enabled ? textTheme.bodySmall?.color : theme.disabledColor,
menuItem.isEnabled ? textTheme.bodySmall?.color : theme.disabledColor,
);

final children = menuChildren;
Expand All @@ -85,7 +86,7 @@ class _MenuButton extends StatelessWidget {
child: IconTheme(
data: IconThemeData(
size: 24,
color: menuItem.enabled
color: menuItem.isEnabled
? textTheme.bodySmall?.color
: theme.disabledColor,
),
Expand Down Expand Up @@ -138,32 +139,29 @@ class _MenuButton extends StatelessWidget {
}

/// Model representing Menu Item
class MenuItem {
final int id;
final String label;
final Widget? icon;
final bool showDivider;
final bool enabled;

MenuItem({
required this.id,
required this.label,
this.icon,
this.showDivider = false,
this.enabled = true,
final class MenuItem extends BasicPopupMenuItem {
const MenuItem({
required super.id,
required super.label,
super.isEnabled = true,
super.icon,
super.showDivider = false,
});
}

/// Model representing Submenu Item
/// and extending from MenuItem
class SubMenuItem extends MenuItem {
List<MenuItem> children;
final class SubMenuItem extends MenuItem {
final List<MenuItem> children;

SubMenuItem({
const SubMenuItem({
required super.id,
required super.label,
required this.children,
super.icon,
super.showDivider,
});

@override
List<Object?> get props => super.props + [children];
}
Loading

0 comments on commit 01db066

Please sign in to comment.