-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcollection_screen.dart
More file actions
93 lines (82 loc) · 3.02 KB
/
collection_screen.dart
File metadata and controls
93 lines (82 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/collectibles_logic.dart';
import 'package:wonders/logic/common/animate_utils.dart';
import 'package:wonders/logic/data/collectible_data.dart';
import 'package:wonders/logic/data/wonder_data.dart';
import 'package:wonders/ui/common/centered_box.dart';
import 'package:wonders/ui/common/controls/app_header.dart';
import 'package:wonders/ui/common/modals/app_modals.dart';
import 'package:wonders/ui/common/utils/duration_utils.dart';
part 'widgets/_collectible_image.dart';
part 'widgets/_collection_footer.dart';
part 'widgets/_collection_list.dart';
part 'widgets/_collection_list_card.dart';
part 'widgets/_newly_discovered_items_btn.dart';
class CollectionScreen extends StatefulWidget with GetItStatefulWidgetMixin {
CollectionScreen({required this.fromId, super.key});
final String fromId;
@override
State<CollectionScreen> createState() => _CollectionScreenState();
}
class _CollectionScreenState extends State<CollectionScreen> with GetItStateMixin {
final GlobalKey _scrollKey = GlobalKey();
@override
void initState() {
super.initState();
final states = collectiblesLogic.statesById.value;
if (widget.fromId.isNotEmpty && states[widget.fromId] == CollectibleState.discovered) {
scheduleMicrotask(() => _scrollToTarget(false));
}
}
void _scrollToTarget([bool animate = true]) {
if (_scrollKey.currentContext != null) {
Scrollable.ensureVisible(
_scrollKey.currentContext!,
alignment: 0.15,
duration: (animate ? 300 : 0).animateMs,
);
}
}
void _handleReset() async {
String msg = $strings.collectionPopupResetConfirm;
final result = await showModal(context, child: OkCancelModal(msg: msg));
if (result == true) {
collectiblesLogic.reset();
}
}
@override
Widget build(BuildContext context) {
// Rebuild when collectible states change
watchX((CollectiblesLogic o) => o.statesById);
int discovered = collectiblesLogic.discoveredCount;
int explored = collectiblesLogic.exploredCount;
int total = collectiblesLogic.all.length;
return ColoredBox(
color: $styles.colors.greyStrong,
child: Column(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
AppHeader(title: $strings.collectionTitleCollection, isTransparent: true),
_NewlyDiscoveredItemsBtn(count: discovered, onPressed: _scrollToTarget),
Flexible(
child: _CollectionList(
fromId: widget.fromId,
scrollKey: _scrollKey,
onReset: discovered + explored > 0 ? _handleReset : null,
),
),
],
),
),
_CollectionFooter(count: discovered + explored, total: total),
],
),
);
}
}