Skip to content

Add contracts screen #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/lib/helpers/contract_helpers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';
// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';
import 'package:threebotlogin/main.dart';

String formatStatus(String text) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest implementing smth like that

  const statusDisplayNames = {
       'created': 'Created',
       'graceperiod': 'Grace Period',
     };

What do u think ?

if (text.isEmpty) return text;

if (text.toLowerCase() == 'graceperiod') {
return 'Grace Period';
} else {
return 'Created';
}
}

String formatDate(int timestamp) {
if (timestamp <= 0) return 'N/A';
try {
final date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
return DateFormat('MMM d, yyyy').format(date);
} catch (e) {
return 'Invalid date';
}
}

Color getStatusColor(String status, BuildContext context) {
final lowerStatus = status.toLowerCase();
switch (lowerStatus) {
case 'graceperiod':
return Theme.of(context).colorScheme.warning;
default:
return Theme.of(context).colorScheme.primary;
}
}

Map<String, Color> getStatusBadgeColors(String status, BuildContext context) {
final lowerStatus = status.toLowerCase();
if (lowerStatus == 'created') {
return {
'background': Theme.of(context).colorScheme.primaryContainer,
'text': Theme.of(context).colorScheme.onPrimaryContainer,
};
} else {
return {
'background': Theme.of(context).colorScheme.warningContainer,
'text': Theme.of(context).colorScheme.onWarningContainer,
};
}
}

Widget buildStatusBadge(BuildContext context, String status) {
final colors = getStatusBadgeColors(status, context);

return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: colors['background'],
borderRadius: BorderRadius.circular(16),
),
child: Text(
formatStatus(status),
style: Theme.of(context).textTheme.labelSmall!.copyWith(
color: colors['text'],
fontWeight: FontWeight.bold,
),
),
);
}
Loading