Skip to content

Commit

Permalink
ui: home_page: show challenges in a dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jjanku committed May 7, 2024
1 parent a3ae6d2 commit cd65471
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/ui/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import 'dart:typed_data';

import 'package:animations/animations.dart';
import 'package:collection/collection.dart';
import 'package:convert/convert.dart';
import 'package:file_picker/file_picker.dart';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide Card;
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:image_picker/image_picker.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:meesign_core/meesign_card.dart';
import 'package:meesign_core/meesign_data.dart';
Expand Down Expand Up @@ -394,6 +396,61 @@ class GroupsSubPage extends StatelessWidget {
class ChallengeSubPage extends StatelessWidget {
const ChallengeSubPage({super.key});

Future<void> showChallengeDialog(
BuildContext context,
Challenge challenge,
) async {
final dataHex = hex.encode(challenge.data);
String? dataStr;
try {
dataStr = utf8.decode(
challenge.data,
allowMalformed: false,
);
} on FormatException {
dataStr = null;
}

await showDialog(
context: context,
builder: (context) {
return AlertDialog(
icon: const Icon(Symbols.quiz),
title: Text(challenge.name),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
dataHex,
style: const TextStyle(
fontFamily: 'RobotoMono',
),
),
if (dataStr != null)
Text(
dataStr,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(.5),
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Hide'),
),
],
);
},
);
}

@override
Widget build(BuildContext context) {
return Consumer<HomeState>(builder: (context, model, child) {
Expand Down Expand Up @@ -425,6 +482,12 @@ class ChallengeSubPage extends StatelessWidget {
child: const Text('Read card'),
),
],
actions: [
FilledButton.tonal(
onPressed: () => showChallengeDialog(context, task.info),
child: const Text('View'),
)
],
onArchiveChange: (archive) =>
model.archiveTask(task, archive: archive),
);
Expand Down

0 comments on commit cd65471

Please sign in to comment.