Skip to content

Commit

Permalink
feat: inkwell unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rannie committed Mar 3, 2020
1 parent 2f279bc commit 1380bd4
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/dynamic/render_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FLDyRenderParser {
return FLDyListViewUnit(unitModel: unitModel);
case FLDyNativeUnitName.listTile:
return FLDyListTileUnit(unitModel: unitModel);
case FLDyNativeUnitName.inkWell:
return FLDyInkWellUnit(unitModel: unitModel);
case FLDyNativeUnitName.text:
return FLDyTextUnit(unitModel: unitModel);
case FLDyNativeUnitName.richText:
Expand Down
34 changes: 34 additions & 0 deletions lib/src/dynamic/units/container_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flui/src/dynamic/units/unit_model.dart';
import 'package:flui/src/dynamic/units/base_unit.dart';
import 'package:flui/src/common/tools.dart';
import 'package:flui/src/dynamic/action/action.dart';

/// Container unit widget
class FLDyContainerUnit extends FLDyRenderUnit {
Expand Down Expand Up @@ -146,3 +147,36 @@ class FLDyListTileUnit extends FLDyRenderUnit {
return resolveSelf(widget);
}
}

/// InkWell unit widget
class FLDyInkWellUnit extends FLDyRenderUnit {
FLDyInkWellUnit({FLDyInkWellUnitModel unitModel})
: assert(unitModel.runtimeType == FLDyInkWellUnitModel),
super(unitModel: unitModel);

@override
Widget build(BuildContext context) {
final FLDyInkWellUnitModel iwum = unitModel as FLDyInkWellUnitModel;
final child = resolveChild();
final InkWell inkWell = InkWell(
child: child,
onTap: () {
FLDyActionDispatch.dispatcher
.dispatchAction(iwum.uniqueId, iwum.onTap, context);
},
onDoubleTap: () {
FLDyActionDispatch.dispatcher
.dispatchAction(iwum.uniqueId, iwum.onDoubleTap, context);
},
onLongPress: () {
FLDyActionDispatch.dispatcher
.dispatchAction(iwum.uniqueId, iwum.onLongPress, context);
},
focusColor: FLThemeTool.parseColor(iwum.focusColor, context),
hoverColor: FLThemeTool.parseColor(iwum.hoverColor, context),
highlightColor: FLThemeTool.parseColor(iwum.highlightColor, context),
splashColor: FLThemeTool.parseColor(iwum.splashColor, context)
);
return resolveSelf(inkWell);
}
}
1 change: 1 addition & 0 deletions lib/src/dynamic/units/unit_constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class FLDyNativeUnitName {
static const String listView = 'ListView';
static const String stack = 'Stack';
static const String listTile = 'ListTile';
static const String inkWell = 'InkWell';
static const String text = 'Text';
static const String richText = 'RichText';
static const String image = 'Image';
Expand Down
41 changes: 41 additions & 0 deletions lib/src/dynamic/units/unit_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class FLDyUnitModel {
return FLDyListViewUnitModel.fromJson(json);
case FLDyNativeUnitName.listTile:
return FLDyListTileUnitModel.fromJson(json);
case FLDyNativeUnitName.inkWell:
return FLDyListTileUnitModel.fromJson(json);
case FLDyNativeUnitName.text:
return FLDyTextUnitModel.fromJson(json);
case FLDyNativeUnitName.richText:
Expand Down Expand Up @@ -257,6 +259,45 @@ class FLDyListTileUnitModel extends FLDyUnitModel {
Map<String, dynamic> toJson() => _$FLDyListTileUnitModelToJson(this);
}

@JsonSerializable()
/// InkWell
class FLDyInkWellUnitModel extends FLDyUnitModel {
FLDyInkWellUnitModel({
String uniqueId,
String unitName,
FLDyUnitAlign align,
FLDyUnitPositioned positioned,
FLDyUnitModel child,
List<FLDyUnitModel> children,
this.onTap,
this.onDoubleTap,
this.onLongPress,
this.focusColor,
this.hoverColor,
this.highlightColor,
this.splashColor,
}) : super(
uniqueId: uniqueId,
unitName: unitName,
align: align,
positioned: positioned,
child: child,
children: children,
);

final FLDyAction onTap;
final FLDyAction onDoubleTap;
final FLDyAction onLongPress;
final String focusColor;
final String hoverColor;
final String highlightColor;
final String splashColor;

factory FLDyInkWellUnitModel.fromJson(Map<String, dynamic> json) =>
_$FLDyInkWellUnitModelFromJson(json);
Map<String, dynamic> toJson() => _$FLDyInkWellUnitModelToJson(this);
}

@JsonSerializable()
/// SizedBox
class FLDySizedBoxUnitModel extends FLDyUnitModel {
Expand Down
53 changes: 53 additions & 0 deletions lib/src/dynamic/units/unit_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1380bd4

Please sign in to comment.