-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
add_edit_item_bottom_sheet.dart
144 lines (131 loc) · 4.56 KB
/
add_edit_item_bottom_sheet.dart
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:genshindb/common/assets.dart';
import '../../../bloc/bloc.dart';
import '../../../common/extensions/iterable_extensions.dart';
import '../../../generated/l10n.dart';
import '../../../models/models.dart';
import '../common/common_bottom_sheet.dart';
import '../common/loading.dart';
import 'skill_item.dart';
class AddEditItemBottomSheet extends StatelessWidget {
final int index;
final String keyName;
final bool isInEditMode;
final bool isAWeapon;
const AddEditItemBottomSheet.toAddItem({
Key key,
@required this.keyName,
@required this.isAWeapon,
}) : index = null,
isInEditMode = false,
super(key: key);
const AddEditItemBottomSheet.toEditItem({
Key key,
@required this.index,
@required this.isAWeapon,
}) : keyName = null,
isInEditMode = true,
super(key: key);
@override
Widget build(BuildContext context) {
final s = S.of(context);
final theme = Theme.of(context);
return BlocBuilder<CalculatorAscMaterialsItemBloc, CalculatorAscMaterialsItemState>(
builder: (context, state) => state.map(
loading: (_) => const Loading(),
loaded: (state) => CommonBottomSheet(
title: state.name,
titleIcon: !isInEditMode ? Icons.add : Icons.edit,
iconSize: 40,
onOk: () => Navigator.of(context).pop(true),
onCancel: () => Navigator.of(context).pop(false),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(s.currentLevel, textAlign: TextAlign.center, style: theme.textTheme.subtitle2),
AscensionLevel(isCurrentLevel: true, level: state.currentLevel),
Container(
margin: const EdgeInsets.only(top: 10),
child: Text(s.desiredLevel, textAlign: TextAlign.center, style: theme.textTheme.subtitle2),
),
AscensionLevel(isCurrentLevel: false, level: state.desiredLevel),
...state.skills
.mapIndex((e, index) => SkillItem(
index: index,
name: e.name,
currentLevel: e.currentLevel,
desiredLevel: e.desiredLevel,
))
.toList()
],
),
),
),
);
}
void _applyChangesForWeapon(
int currentLevel,
int desiredLevel,
BuildContext context,
) {
if (!isInEditMode) {
context
.read<CalculatorAscMaterialsBloc>()
.add(CalculatorAscMaterialsEvent.addWeapon(key: keyName, currentLevel: currentLevel, desiredLevel: desiredLevel));
return;
}
context
.read<CalculatorAscMaterialsBloc>()
.add(CalculatorAscMaterialsEvent.updateWeapon(index: 1, currentLevel: currentLevel, desiredLevel: desiredLevel));
}
void _applyChangesForCharacter(
int currentLevel,
int desiredLevel,
List<CharacterSkill> skills,
BuildContext context,
) {
if (!isInEditMode) {
context
.read<CalculatorAscMaterialsBloc>()
.add(CalculatorAscMaterialsEvent.addCharacter(key: keyName, currentLevel: currentLevel, desiredLevel: desiredLevel, skills: skills));
}
}
}
class AscensionLevel extends StatelessWidget {
final bool isCurrentLevel;
final int level;
const AscensionLevel({
Key key,
@required this.isCurrentLevel,
@required this.level,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final widgets = <Widget>[];
for (var i = CalculatorAscMaterialsItemBloc.minAscensionLevel; i < CalculatorAscMaterialsItemBloc.maxAscensionLevel; i++) {
final isSelected = level > 0 && i <= level;
final button = IconButton(
icon: Opacity(
opacity: isSelected ? 1 : 0.2,
child: Image.asset(Assets.getOtherMaterialPath('mark_wind_crystal.png'), width: 40, height: 40),
),
onPressed: () {
final bloc = context.read<CalculatorAscMaterialsItemBloc>();
if (isCurrentLevel) {
bloc.add(CalculatorAscMaterialsItemEvent.currentLevelChanged(newValue: i));
} else {
bloc.add(CalculatorAscMaterialsItemEvent.desiredLevelChanged(newValue: i));
}
},
);
widgets.add(button);
}
return Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.center,
children: widgets,
);
}
}