-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [MDS-669] Fix InputGroup bugs (#250)
- Loading branch information
Showing
14 changed files
with
388 additions
and
234 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,93 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:moon_design/moon_design.dart'; | ||
|
||
/// Used to animate the border of a container. Mainly used in [MoonTextInput] and [MoonTextInputGroup] | ||
class BorderContainer extends StatefulWidget { | ||
final Color backgroundColor; | ||
final Decoration? decoration; | ||
final double? height; | ||
|
||
final ShapeBorder border; | ||
final Duration duration; | ||
final Curve curve; | ||
final Widget child; | ||
|
||
/// Utility widget used to animate the border of a container. | ||
const BorderContainer({ | ||
required this.backgroundColor, | ||
this.decoration, | ||
required this.height, | ||
required this.border, | ||
required this.duration, | ||
required this.curve, | ||
required this.child, | ||
}); | ||
|
||
@override | ||
_BorderContainerState createState() => _BorderContainerState(); | ||
} | ||
|
||
class _BorderContainerState extends State<BorderContainer> with TickerProviderStateMixin { | ||
late AnimationController _controller; | ||
late Animation<double> _borderAnimation; | ||
late ShapeBorderTween _border; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_controller = AnimationController( | ||
duration: widget.duration, | ||
vsync: this, | ||
); | ||
_borderAnimation = CurvedAnimation( | ||
parent: _controller, | ||
curve: widget.curve, | ||
reverseCurve: widget.curve.flipped, | ||
); | ||
_border = ShapeBorderTween( | ||
begin: widget.border, | ||
end: widget.border, | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_controller.dispose(); | ||
|
||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(BorderContainer oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
if (widget.border != oldWidget.border) { | ||
_border = ShapeBorderTween( | ||
begin: oldWidget.border, | ||
end: widget.border, | ||
); | ||
_controller | ||
..value = 0.0 | ||
..forward(); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AnimatedBuilder( | ||
animation: _borderAnimation, | ||
builder: (context, child) { | ||
return Container( | ||
height: widget.height, | ||
decoration: widget.decoration ?? | ||
ShapeDecorationWithPremultipliedAlpha( | ||
color: widget.backgroundColor, | ||
shape: _border.evaluate(_borderAnimation)!, | ||
), | ||
child: child, | ||
); | ||
}, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:moon_design/src/theme/theme.dart'; | ||
import 'package:moon_design/src/widgets/common/icons/icons.dart'; | ||
import 'package:moon_design/src/widgets/common/icons/moon_icon.dart'; | ||
|
||
class MoonErrorMessages extends StatelessWidget { | ||
final List<String> errors; | ||
|
||
/// Default error message widget used in [MoonTextInputGroup]. | ||
const MoonErrorMessages({required this.errors}); | ||
|
||
List<String> get _nonEmptyErrors => errors.where((String error) => error.isNotEmpty).toList(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: List.generate(_nonEmptyErrors.length * 2 - 1, (int index) { | ||
final int derivedIndex = index ~/ 2; | ||
|
||
return index.isEven | ||
? MoonErrorMessage(errorText: _nonEmptyErrors[derivedIndex]) | ||
: SizedBox(height: context.moonSizes?.x5s ?? 4); | ||
}), | ||
); | ||
} | ||
} | ||
|
||
class MoonErrorMessage extends StatelessWidget { | ||
final String errorText; | ||
|
||
/// Default error message widget used in [MoonTextInput] and [MoonTextArea]. | ||
const MoonErrorMessage({ | ||
super.key, | ||
required this.errorText, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Row( | ||
children: [ | ||
MoonIcon(MoonIcons.info_16, size: context.moonSizes?.x2s ?? 16), | ||
SizedBox(width: context.moonSizes?.x5s ?? 4), | ||
Text(errorText), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.