Skip to content

Commit

Permalink
Merge pull request #32 from ReinBentdal/development
Browse files Browse the repository at this point in the history
0.8.2
  • Loading branch information
ReinBentdal authored Sep 17, 2019
2 parents 1d21a6b + 52d0413 commit a8acee6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 73 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.8.2
* Added `onEditingComplete` parameter to the editable method in `TxtStyle`
* Added `textDecoration` to `TxtStyle`
* Added `maxLines` parameter to the `editable` method
* [Fix] `Ripple` not working when `BoxDecoration` is null

## 0.8.1
* Added `placeholder` parameter to the editable method in `TxtStyle`
* Added `clone` method to be able to clone a `StyleClass`
Expand Down
1 change: 0 additions & 1 deletion example/example/example_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class _TestState extends State<Test> {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

// Title
Txt(
'Login',
Expand Down
43 changes: 4 additions & 39 deletions example/readme.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
# Example 1
# Example showcase

## Preview
App designer: [Link](https://dribbble.com/shots/6459693-Creative-layout-design)

<img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/demo_app.gif" width="400">

## Code

[Example 1 code](https://github.com/ReinBentdal/division/blob/master/example/example/example_1.dart)

# Example 2

## Preview

<img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/frosted_glass_demo.gif" width="400">

## Code

[Example 2 code](https://github.com/ReinBentdal/division/blob/master/example/example/example_2.dart)

# Example 3

## Preview

<img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/demo_app_2.png" width="400">

## Code

[Example 3 code](https://github.com/ReinBentdal/division/blob/master/example/example/example_3.dart)

# Example 4

## Preview

<img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/elevation_demo.png" width="400">

## Code

[Example 4 code](https://github.com/ReinBentdal/division/blob/master/example/example/example_4.dart)
| [Design](https://dribbble.com/shots/6459693-Creative-layout-design), [code](https://github.com/ReinBentdal/division/blob/master/example/example/example_1.dart) | [Code](https://github.com/ReinBentdal/division/blob/master/example/example/example_2.dart) | <span style="text-align: center; display: block;">**[Code](https://github.com/ReinBentdal/division/blob/master/example/example/example_form.dart)**</span> |
|-|-|-|
| <img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/demo_app.gif" width="200"> | <img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/frosted_glass_demo.gif" width="200"> | <img src="https://raw.githubusercontent.com/ReinBentdal/division/master/example/assets/form_demo.gif" width="200"> |
22 changes: 18 additions & 4 deletions lib/src/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ParentBuild extends StatelessWidget {
color: Colors.transparent,
child: InkWell(
onTap: gestureModel?.onTap ?? () {},
borderRadius: decoration.borderRadius,
borderRadius: decoration?.borderRadius,
highlightColor: styleModel?.ripple?.highlightColor,
splashColor: styleModel?.ripple?.splashColor,
child: widgetTree,
Expand Down Expand Up @@ -192,9 +192,7 @@ class TxtBuild extends StatelessWidget {
}

class TxtBuildEditable extends StatefulWidget {
TxtBuildEditable(
{@required this.text,
@required this.textModel});
TxtBuildEditable({@required this.text, @required this.textModel});

final String text;
final TextModel textModel;
Expand All @@ -214,6 +212,17 @@ class _TxtBuildEditableState extends State<TxtBuildEditable> {
_initializeFocusNode();
}

@override
void didUpdateWidget(TxtBuildEditable oldWidget) {
super.didUpdateWidget(oldWidget);

if (widget.text != _controller.text) {
setState(() {
_controller = TextEditingController(text: widget.text);
});
}
}

void _initializeFocusNode() {
if (_focusNode == null)
_focusNode = widget.textModel?.focusNode ?? FocusNode();
Expand Down Expand Up @@ -268,6 +277,11 @@ class _TxtBuildEditableState extends State<TxtBuildEditable> {
keyboardType: widget.textModel?.keyboardType ?? TextInputType.text,
onChanged: widget.textModel?.onChange,
onSelectionChanged: widget.textModel?.onSelectionChanged,
onEditingComplete: () {
_focusNode?.unfocus();
_controller?.clearComposing();
widget.textModel?.onEditingComplete();
},
);
}
}
80 changes: 51 additions & 29 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,35 @@ class AlignmentModel with ChangeNotifier {

AlignmentGeometry get getAlignment => _alignment;

void topLeft() => _updateAlignment(Alignment.topLeft);
void topCenter() => _updateAlignment(Alignment.topCenter);
void topRight() => _updateAlignment(Alignment.topRight);

void bottomLeft() => _updateAlignment(Alignment.bottomLeft);
void bottomCenter() => _updateAlignment(Alignment.bottomCenter);
void bottomRight() => _updateAlignment(Alignment.bottomRight);

void centerLeft() => _updateAlignment(Alignment.centerLeft);
void center() => _updateAlignment(Alignment.center);
void centerRight() => _updateAlignment(Alignment.centerRight);

void coordinate(double x, double y) => _updateAlignment(Alignment(x, y));

void _updateAlignment(AlignmentGeometry alignment) {
_alignment = alignment;
notifyListeners();
void topLeft([bool enable = true]) =>
_updateAlignment(Alignment.topLeft, enable);
void topCenter([bool enable = true]) =>
_updateAlignment(Alignment.topCenter, enable);
void topRight([bool enable = true]) =>
_updateAlignment(Alignment.topRight, enable);

void bottomLeft([bool enable = true]) =>
_updateAlignment(Alignment.bottomLeft, enable);
void bottomCenter([bool enable = true]) =>
_updateAlignment(Alignment.bottomCenter, enable);
void bottomRight([bool enable = true]) =>
_updateAlignment(Alignment.bottomRight, enable);

void centerLeft([bool enable = true]) =>
_updateAlignment(Alignment.centerLeft, enable);
void center([bool enable = true]) =>
_updateAlignment(Alignment.center, enable);
void centerRight([bool enable = true]) =>
_updateAlignment(Alignment.centerRight, enable);

void coordinate(double x, double y, [bool enable = true]) =>
_updateAlignment(Alignment(x, y), enable);

void _updateAlignment(AlignmentGeometry alignment, bool enable) {
if (enable) {
_alignment = alignment;
notifyListeners();
}
}
}

Expand Down Expand Up @@ -386,6 +398,7 @@ class TextModel {
int maxLines;
double letterSpacing;
double wordSpacing;
TextDecoration textDecoration;

//editable
bool editable;
Expand All @@ -395,8 +408,8 @@ class TextModel {

void Function(String) onChange;
void Function(bool focus) onFocusChange;
void Function(TextSelection, SelectionChangedCause)
onSelectionChanged;
void Function(TextSelection, SelectionChangedCause) onSelectionChanged;
void Function() onEditingComplete;
FocusNode focusNode;

void inject(TextModel textModel, bool override) {
Expand All @@ -411,13 +424,17 @@ class TextModel {
maxLines = _replace(maxLines, textModel?.maxLines, override);
letterSpacing = _replace(letterSpacing, textModel?.letterSpacing, override);
wordSpacing = _replace(wordSpacing, textModel?.wordSpacing, override);
textDecoration =
_replace(textDecoration, textModel?.textDecoration, override);

editable = _replace(editable, textModel?.editable, override);
keyboardType = _replace(keyboardType, textModel?.keyboardType, override);
onChange = _replace(onChange, textModel?.onChange, override);
onFocusChange = _replace(onFocusChange, textModel?.onFocusChange, override);
onSelectionChanged =
_replace(onSelectionChanged, textModel?.onSelectionChanged, override);
onEditingComplete =
_replace(onEditingComplete, textModel?.onEditingComplete, override);
focusNode = _replace(focusNode, textModel?.focusNode, override);
}

Expand All @@ -438,6 +455,7 @@ class TextModel {
fontFamilyFallback: fontFamilyFallback,
letterSpacing: letterSpacing,
wordSpacing: wordSpacing,
decoration: textDecoration,
);
}
}
Expand All @@ -447,15 +465,19 @@ class TextAlignModel with ChangeNotifier {

TextAlign get exportTextAlign => _textAlign;

void left() => _updateAlignment(TextAlign.left);
void right() => _updateAlignment(TextAlign.right);
void center() => _updateAlignment(TextAlign.center);
void justify() => _updateAlignment(TextAlign.justify);
void start() => _updateAlignment(TextAlign.start);
void end() => _updateAlignment(TextAlign.end);

_updateAlignment(TextAlign textAlign) {
_textAlign = textAlign;
notifyListeners();
void left([bool enable = true]) => _updateAlignment(TextAlign.left, enable);
void right([bool enable = true]) => _updateAlignment(TextAlign.right, enable);
void center([bool enable = true]) =>
_updateAlignment(TextAlign.center, enable);
void justify([bool enable = true]) =>
_updateAlignment(TextAlign.justify, enable);
void start([bool enable = true]) => _updateAlignment(TextAlign.start, enable);
void end([bool enable = true]) => _updateAlignment(TextAlign.end, enable);

_updateAlignment(TextAlign textAlign, bool enable) {
if (enable == true) {
_textAlign = textAlign;
notifyListeners();
}
}
}
7 changes: 7 additions & 0 deletions lib/src/style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -742,25 +742,32 @@ class TxtStyle extends StyleClass {

void wordSpacing(double space) => _textModel?.wordSpacing = space;

void textDecoration(TextDecoration decoration) =>
_textModel?.textDecoration = decoration;

/// Make the widget editable just like a TextField.
///
/// If `focusNode` isnt spesified an internal `focusNode` will be created.
void editable(bool enable,
{TextInputType keyboardType,
String placeholder,
bool obscureText = false,
int maxLines,
void Function(String) onChange,
void Function(bool focus) onFocusChange,
void Function(TextSelection, SelectionChangedCause) onSelectionChanged,
void Function() onEditingComplete,
FocusNode focusNode}) {
_textModel
..editable = enable
..keyboardType = keyboardType
..placeholder = placeholder
..obscureText = obscureText
..maxLines = maxLines
..onChange = onChange
..onFocusChange = onFocusChange
..onSelectionChanged = onSelectionChanged
..onEditingComplete = onEditingComplete
..focusNode = focusNode;
}

Expand Down

0 comments on commit a8acee6

Please sign in to comment.