-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ConstrainedBox attributes, model, widget variants
- Loading branch information
Showing
13 changed files
with
204 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extension type AnimatedPropHelper(Map<String, dynamic> json) implements Map { | ||
String? get parentBuilderId => json["parentBuilderId"]; | ||
|
||
Iterable<String>? get affectedProperties { | ||
if (json.containsKey("affectedProperties")) { | ||
return Set.from(json["affectedProperties"]); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "package:duit_kernel/duit_kernel.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_duit/flutter_duit.dart"; | ||
import "package:flutter_duit/src/animations/animated_prop_helper.dart"; | ||
|
||
final class ConstrainedBoxAttributes extends AnimatedPropertyOwner | ||
implements DuitAttributes<ConstrainedBoxAttributes> { | ||
final BoxConstraints constraints; | ||
|
||
ConstrainedBoxAttributes({ | ||
required super.parentBuilderId, | ||
required super.affectedProperties, | ||
required this.constraints, | ||
}); | ||
|
||
factory ConstrainedBoxAttributes.fromJson(Map<String, dynamic> json) { | ||
final props = AnimatedPropHelper(json); | ||
|
||
return ConstrainedBoxAttributes( | ||
parentBuilderId: props.parentBuilderId, | ||
affectedProperties: props.affectedProperties, | ||
constraints: AttributeValueMapper.toBoxConstraints(props["constraints"]), | ||
); | ||
} | ||
|
||
@override | ||
ConstrainedBoxAttributes copyWith(ConstrainedBoxAttributes other) { | ||
return ConstrainedBoxAttributes( | ||
constraints: other.constraints, | ||
parentBuilderId: other.parentBuilderId ?? parentBuilderId, | ||
affectedProperties: other.affectedProperties ?? affectedProperties, | ||
); | ||
} | ||
|
||
@override | ||
ReturnT dispatchInternalCall<ReturnT>( | ||
String methodName, { | ||
Iterable? positionalParams, | ||
Map<String, dynamic>? namedParams, | ||
}) { | ||
return switch (methodName) { | ||
"fromJson" => | ||
ConstrainedBoxAttributes.fromJson(positionalParams!.first) as ReturnT, | ||
String() => throw UnimplementedError("$methodName is not implemented"), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:flutter_duit/src/attributes/index.dart'; | ||
import 'package:flutter_duit/src/ui/models/element_models.dart'; | ||
|
||
//Type helpers for better type assertion | ||
|
||
typedef ConstrainedBoxModel = ConstrainedBoxUIElement<ConstrainedBoxAttributes>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import "package:duit_kernel/duit_kernel.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_duit/flutter_duit.dart"; | ||
import "package:flutter_duit/src/animations/index.dart"; | ||
import "package:flutter_duit/src/attributes/index.dart"; | ||
|
||
class DuitConstrainedBox extends StatelessWidget with AnimatedAttributes { | ||
final Widget child; | ||
final ViewAttribute<ConstrainedBoxAttributes> attributes; | ||
|
||
const DuitConstrainedBox({ | ||
super.key, | ||
required this.child, | ||
required this.attributes, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final attrs = mergeWithAttributes( | ||
context, | ||
attributes.payload, | ||
); | ||
|
||
return ConstrainedBox( | ||
key: ValueKey(attributes.id), | ||
constraints: attrs.constraints, | ||
child: child, | ||
); | ||
} | ||
} | ||
|
||
class DuitControlledConstrainedBox extends StatefulWidget | ||
with AnimatedAttributes { | ||
final Widget child; | ||
final UIElementController<ConstrainedBoxAttributes> controller; | ||
|
||
const DuitControlledConstrainedBox({ | ||
super.key, | ||
required this.child, | ||
required this.controller, | ||
}); | ||
|
||
@override | ||
State<DuitControlledConstrainedBox> createState() => | ||
_DuitControlledConstrainedBoxState(); | ||
} | ||
|
||
class _DuitControlledConstrainedBoxState | ||
extends State<DuitControlledConstrainedBox> | ||
with | ||
ViewControllerChangeListener<DuitControlledConstrainedBox, | ||
ConstrainedBoxAttributes> { | ||
@override | ||
void initState() { | ||
attachStateToController(widget.controller); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final attrs = widget.mergeWithAttributes( | ||
context, | ||
attributes, | ||
); | ||
|
||
return ConstrainedBox( | ||
key: ValueKey(widget.controller.id), | ||
constraints: attrs.constraints, | ||
child: widget.child, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters