Skip to content

Commit

Permalink
refactor (MiraiSwitch): Cubit replaced with StatefulWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalmahapatro committed Sep 24, 2023
1 parent c243527 commit b7b3b91
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 63 deletions.
3 changes: 2 additions & 1 deletion examples/mirai_gallery/assets/json/switch_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
{
"type": "switchButton",
"initialValue": false,
"onChanged": {}
"onChanged": {},
"activeColor": "#FF0000"
}
]
},
Expand Down

This file was deleted.

This file was deleted.

35 changes: 35 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_switch/mirai_switch.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
import 'dart:ui';

import 'package:flutter/gestures.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mirai/mirai.dart';

part 'mirai_switch.freezed.dart';
part 'mirai_switch.g.dart';

@freezed
class MiraiSwitch with _$MiraiSwitch {
const MiraiSwitch._();

const factory MiraiSwitch({
@Default(false) initialValue,
Map<String, dynamic>? onChanged,
@Default(false) bool autofocus,
@Default(false) bool disabled,
String? activeColor,
String? activeTrackColor,
String? focusColor,
String? hoverColor,
String? inactiveThumbColor,
String? inactiveTrackColor,
double? splashRadius,
String? dragStartBehavior,
}) = _MiraiSwitch;

factory MiraiSwitch.fromJson(Map<String, dynamic> json) =>
_$MiraiSwitchFromJson(json);

DragStartBehavior get dragStateBehaviorValue {
return DragStartBehavior.values.firstWhere(
(element) => element.name == dragStartBehavior,
orElse: () => DragStartBehavior.start,
);
}

Color? get activeColorValue => activeColor?.toColor;

Color? get activeTrackColorValue => activeTrackColor?.toColor;

Color? get focusColorValue => focusColor?.toColor;

Color? get hoverColorValue => hoverColor?.toColor;

Color? get inactiveThumbColorValue => inactiveThumbColor?.toColor;

Color? get inactiveTrackColorValue => inactiveTrackColor?.toColor;
}
Loading

0 comments on commit b7b3b91

Please sign in to comment.