Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
size change listener and misc
Browse files Browse the repository at this point in the history
  • Loading branch information
aprosail committed May 16, 2024
2 parents eeee180 + e958987 commit 19ed631
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.0

- Widget size change listener.
- Wrap padding (edge insets).
- Text wrapper on string with parameters.

## 0.4.1

- Doc alert value modify cover in the same context.
Expand Down
28 changes: 28 additions & 0 deletions lib/src/size.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/widgets.dart';

extension WrapSize on Widget {
/// Listen the size change of this widget and handle [listener] as hook.
///
/// This wrapper should be placed close to root of the widget tree,
/// the size is based on the context of this widget,
/// so that the inner size change listener should be close to
/// where the context is build, or there might be potential conflicts.
Widget listenSizeChange(
BuildContext context,
void Function(Size size) listener,
) {
return NotificationListener(
onNotification: (notification) {
if (notification is SizeChangedLayoutNotification) {
listener(context.size ?? MediaQuery.of(context).size);
return true;
}
return false;
},
child: SizeChangedLayoutNotifier(child: this),
);
}

Widget wrapPadding(EdgeInsets padding) =>
Padding(padding: padding, child: this);
}
5 changes: 5 additions & 0 deletions lib/src/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ extension WrapTextEnvironment on Widget {
extension StringToTextWidget on String {
/// Convert a [String] into a [Text] widget.
Widget get textWidget => Text(this);

/// If there's no parameter to modify, consider using [textWidget] instead,
/// which is a getter rather than method,
/// with better performance and conciser code style.
Widget text({TextAlign? align}) => Text(this, textAlign: align);
}

extension WrapTextStyle on Widget {
Expand Down
1 change: 1 addition & 0 deletions lib/wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export 'src/context.dart';
export 'src/decorate.dart';
export 'src/list.dart';
export 'src/media.dart';
export 'src/size.dart';
export 'src/text.dart';
8 changes: 7 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: wrap
description: Chain style programming syntax sugar utilities for flutter widgets.
version: 0.4.1
version: 0.5.0
repository: https://github.com/aprosail/wrap
environment: {sdk: ">=3.3.4 <4.0.0", flutter: ">=3.19.6"}
topics:
- syntax-sugar
- code-style
- chain-style
- chain-programming
- flutter-widgets

dependencies:
flutter: {sdk: flutter}
Expand Down

0 comments on commit 19ed631

Please sign in to comment.