Skip to content

Commit

Permalink
WIP - Initial prototyping of positioned widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Oct 29, 2023
1 parent bbcd4a6 commit 3c0ecaa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
19 changes: 10 additions & 9 deletions stevia/lib/src/services/text_input_formatters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ class IntTextInputFormatter extends TextInputFormatter {

@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
if (newValue.text.isEmpty || newValue.text == '-') {
final TextEditingValue(:text, :selection, :composing) = newValue;
if (text.isEmpty || text == '-') {
return newValue;
}

final trimmed = newValue.text.trim().replaceAll(',', '');
final trimmed = text.trim().replaceAll(',', '');
return switch (int.tryParse(trimmed)) {
final value? when _range.contains(value) => switch (newValue.text.length == trimmed.length) {
final value? when _range.contains(value) => switch (text.length == trimmed.length) {
true => newValue,
false => TextEditingValue(
text: trimmed,
selection: newValue.selection.copyWith(
baseOffset: math.min(newValue.selection.start, trimmed.length),
extentOffset: math.min(newValue.selection.end, trimmed.length),
selection: selection.copyWith(
baseOffset: math.min(selection.start, trimmed.length),
extentOffset: math.min(selection.end, trimmed.length),
),
composing: !newValue.composing.isCollapsed && trimmed.length > newValue.composing.start ? TextRange(
start: newValue.composing.start,
end: math.min(newValue.composing.end, trimmed.length),
composing: !composing.isCollapsed && trimmed.length > composing.start ? TextRange(
start: composing.start,
end: math.min(composing.end, trimmed.length),
): TextRange.empty,
)
},
Expand Down
29 changes: 29 additions & 0 deletions stevia/lib/src/widgets/positioned/positioned_route.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/cupertino.dart';
import 'package:meta/meta.dart';

class PositionedRoute extends PopupRoute<void> {

@override
final Color? barrierColor;
@override
final String? barrierLabel;
@override
final bool barrierDismissible;
@override
final Duration transitionDuration;

/// Creates a [PositionedRoute].
PositionedRoute({
this.barrierLabel,
this.barrierColor,
this.barrierDismissible = true,
this.transitionDuration = const Duration(milliseconds: 300),
});

@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
// TODO: implement buildPage
throw UnimplementedError();
}

}
2 changes: 1 addition & 1 deletion stevia/lib/src/widgets/resizable/resizable_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:stevia/src/widgets/resizable/resizable_region_change_notifier.da

/// A box which children can all be resized either horizontally or vertically.
///
/// Each child must be selected by tapping on it before it can be resized.
/// Each child is a [ResizableRegion] that must be selected by tapping on it before it can be resized.
///
/// ## Contract
/// Each child has a minimum size determined by its slider size multiplied by 2. Setting an initial size smaller
Expand Down

0 comments on commit 3c0ecaa

Please sign in to comment.