Skip to content

Commit fe85dac

Browse files
committed
refactor: Add explicit types and adopt modern Dart syntax
This commit introduces several code quality improvements by adding explicit type annotations and adopting modern Dart syntax. - **Type Safety**: - Added explicit `void` return types to methods that previously had implicit `dynamic` returns (e.g., `modify` methods in `continuous`, `durability`, `wetness`, and `freshness` item components, `setGameSave`/`deleteGameSave` in `db.dart`, and `reload` in `foundation.dart`). - Specified `double` and `void` return types for operators in `AttributeManagerProtocolX`. - Made `_key2Translated` and `_fallbackKey2Translated` maps in `Mod` final. - **Modernization**: - Migrated to super-initializer parameters in widget constructors (`Top`, `_LocalTop`, `_IconsXData`). - Updated `AlertDialog` to use `context.theme.dialogTheme.backgroundColor` instead of the deprecated `dialogBackgroundColor`. - Corrected a typo in `ColorUtils.mergeColors` from `a.opacity` to `a.a`. - Updated the package name in `r.dart` from `net.liplum.escape_wild.flutter` to `net.liplum.escape_wild`.
1 parent ed141cb commit fe85dac

File tree

13 files changed

+20
-21
lines changed

13 files changed

+20
-21
lines changed

lib/core/attribute/attribute.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ abstract class AttributeManagerProtocol {
8585
}
8686

8787
extension AttributeManagerProtocolX on AttributeManagerProtocol {
88-
operator [](Attr attr) => getAttr(attr);
88+
double operator [](Attr attr) => getAttr(attr);
8989

90-
operator []=(Attr attr, double value) => setAttr(attr, value);
90+
void operator []=(Attr attr, double value) => setAttr(attr, value);
9191

9292
double get health => this[Attr.health];
9393

@@ -312,5 +312,5 @@ class AttrModifierBuilder {
312312
}
313313

314314
extension AttrModifierBuilderX on AttrModifierBuilder {
315-
operator <<(AttrModifier modifier) => add(modifier);
315+
void operator <<(AttrModifier modifier) => add(modifier);
316316
}

lib/core/item/continuous/continuous.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ContinuousModifyMassComp extends ItemComp {
6666
modify(stack, delta, deltaPerMinute);
6767
}
6868

69-
static modify(ItemStack stack, Ts timePassed, double deltaPerMinute) {
69+
static void modify(ItemStack stack, Ts timePassed, double deltaPerMinute) {
7070
final totalDelta = deltaPerMinute * timePassed.minutes;
7171
if (stack.meta.mergeable) {
7272
stack.mass = stack.stackMass + totalDelta.toInt();

lib/core/item/durability/durability.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ContinuousModifyDurabilityComp extends ItemComp {
140140
modify(stack, delta, deltaPerMinute, wetFactor: wetFactor);
141141
}
142142

143-
static modify(ItemStack stack, Ts timePassed, double deltaPerMinute, {double wetFactor = 0.0}) {
143+
static void modify(ItemStack stack, Ts timePassed, double deltaPerMinute, {double wetFactor = 0.0}) {
144144
var totalDelta = deltaPerMinute * timePassed.minutes;
145145
final comp = DurabilityComp.of(stack);
146146
if (comp != null) {

lib/core/item/freshness/freshness.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ContinuousModifyFreshnessComp extends ItemComp {
142142
modify(stack, delta, deltaPerMinute, wetFactor: wetFactor);
143143
}
144144

145-
static modify(ItemStack stack, Ts timePassed, double deltaPerMinute, {double wetFactor = 0.0}) {
145+
static void modify(ItemStack stack, Ts timePassed, double deltaPerMinute, {double wetFactor = 0.0}) {
146146
var totalDelta = deltaPerMinute * timePassed.minutes;
147147
final comp = FreshnessComp.of(stack);
148148
if (comp != null) {

lib/core/item/wetness/wetness.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ContinuousModifyWetnessComp extends ItemComp {
112112
modify(stack, delta, deltaPerMinute);
113113
}
114114

115-
static modify(ItemStack stack, Ts timePassed, double deltaPerMinute) {
115+
static void modify(ItemStack stack, Ts timePassed, double deltaPerMinute) {
116116
final totalDelta = deltaPerMinute * timePassed.minutes;
117117
final comp = WetnessComp.of(stack);
118118
if (comp != null) {

lib/core/mod/mod.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Mod implements ModProtocol {
3333

3434
Mod(this.modId);
3535

36-
var _key2Translated = <String, String>{};
36+
final _key2Translated = <String, String>{};
3737

3838
/// Used when key not found in current locale.
39-
var _fallbackKey2Translated = <String, String>{};
39+
final _fallbackKey2Translated = <String, String>{};
4040

4141
@override
4242
String decorateRegisterName(String name) => "$modId-$name";

lib/db.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class DBImpl {
1616

1717
String? getGameSave({int slot = 0}) => $gameSave.get(slot);
1818

19-
setGameSave(String save, {int slot = 0}) => $gameSave.put(slot, save);
19+
Future<void> setGameSave(String save, {int slot = 0}) => $gameSave.put(slot, save);
2020

21-
deleteGameSave({int slot = 0}) => $gameSave.delete(slot);
21+
Future<void> deleteGameSave({int slot = 0}) => $gameSave.delete(slot);
2222
}
2323

2424
class Preference {

lib/design/dialog.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class $Dialog$ extends StatelessWidget {
292292
} else {
293293
// For other platform
294294
dialog = AlertDialog(
295-
backgroundColor: context.theme.dialogBackgroundColor,
295+
backgroundColor: context.theme.dialogTheme.backgroundColor,
296296
title: title?.text(style: TextStyle(fontWeight: FontWeight.w600, color: destructive ? context.$red$ : null)),
297297
content: builder(context),
298298
actions: [

lib/design/top.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ class Top extends StatelessWidget {
178178
final bool global;
179179

180180
const Top({
181-
Key? key,
181+
super.key,
182182
required this.child,
183183
this.global = true,
184-
}) : super(key: key);
184+
});
185185

186186
const Top.global({
187187
super.key,
@@ -275,9 +275,9 @@ class _LocalTop extends StatefulWidget {
275275
final Widget child;
276276

277277
const _LocalTop({
278-
Key? key,
278+
super.key,
279279
required this.child,
280-
}) : super(key: key);
280+
});
281281

282282
@override
283283
_LocalTopState createState() => _LocalTopState();

lib/foundation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Measurement {
3434

3535
static var mass = UnitConverter.gram;
3636

37-
static reload() {
37+
static void reload() {
3838
Measurement.mass = UnitConverter.getMassForName(DB.preference.getMeasurementSystemOf(PhysicalQuantity.mass.name));
3939
}
4040

0 commit comments

Comments
 (0)