Skip to content

Commit

Permalink
Merge branch 'letsar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstef99 authored May 13, 2022
2 parents 9247e93 + 60087b1 commit b71fe8a
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.2.0
### Added
* A way to automatically close other Slidables within the same group by tapping on them.
* Add a dragDismissible parameter on ActionPane.
### Fixed
* The RTL issue (#244).

## 1.1.0
### Changed
* Created a totally different notification system in order to be more flexible.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Our top sponsors are shown below! [[Become a Sponsor](https://github.com/sponsor
<tbody>
<tr>
<td align="center">
<a href="https://getstream.io/chat/flutter/tutorial/?utm_source=https://github.com/letsar/flutter_slidable&utm_medium=github&utm_content=developer&utm_term=flutter" target="_blank"><img width="250px" src="https://stream-blog.s3.amazonaws.com/blog/wp-content/uploads/fc148f0fc75d02841d017bb36e14e388/Stream-logo-with-background-.png"/></a><br/><span><a href="https://getstream.io/chat/flutter/tutorial/?utm_source=https://github.com/letsar/flutter_slidable&utm_medium=github&utm_content=developer&utm_term=flutter" target="_blank">Try the Flutter Chat Tutorial &nbsp💬</a></span>
<a href="https://getstream.io/chat/flutter/tutorial/?utm_source=PubDev&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=PubDev_Jan2022_FlutterChat&utm_term=slidable" target="_blank"><img width="250px" src="https://stream-blog.s3.amazonaws.com/blog/wp-content/uploads/fc148f0fc75d02841d017bb36e14e388/Stream-logo-with-background-.png"/></a><br/><span><a href="https://getstream.io/chat/flutter/tutorial/?utm_source=PubDev&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=PubDev_Jan2022_FlutterChat&utm_term=slidable" target="_blank">Try the Flutter Chat Tutorial &nbsp💬</a></span>
</td>
</tr>
</tbody>
Expand Down
202 changes: 202 additions & 0 deletions example/lib/main_issue_251.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Slidable Example',
home: Scaffold(
body: ListView(
children: const [
ListItem(
title: 'ERIC',
subtitle: 'Subtitle 1',
),
ListItem(
title: 'ERIC',
subtitle: 'Subtitle 2',
),
ListItem(
title: 'ERIC',
subtitle: 'Subtitle 3',
),
ListItem(
title: 'ERIC',
subtitle: 'Subtitle 4',
),
],
),
),
);
}
}

class ListItem extends StatefulWidget {
const ListItem({
Key? key,
required this.title,
required this.subtitle,
}) : super(key: key);

final String title;
final String subtitle;

@override
State<ListItem> createState() => _ListItemState();
}

class _ListItemState extends State<ListItem> {
final colorNotifier = ValueNotifier<Color>(Colors.grey);

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return SizedBox(
height: 50,
child: Slidable(
startActionPane: ActionPane(
closeThreshold: 0.5,
openThreshold: 0.6,
extentRatio: 0.5,
motion: const BehindMotion(),
children: [RememberedArea(colorNotifier: colorNotifier)],
),
child: Row(
children: [
Hint(colorNotifier: colorNotifier),
Expanded(
child: Item(
title: widget.title,
subtitle: widget.subtitle,
),
)
],
),
),
);
}
}

class RememberedArea extends StatefulWidget {
RememberedArea({
Key? key,
required this.colorNotifier,
ColorTween? colorTween,
}) : colorTween = colorTween ??
ColorTween(
begin: Colors.yellow,
end: Colors.green,
),
super(key: key);

final ColorTween colorTween;
final ValueNotifier<Color> colorNotifier;

@override
State<RememberedArea> createState() => _RememberedAreaState();
}

class _RememberedAreaState extends State<RememberedArea> {
double maxValue = 0;
late final animation = Slidable.of(context)!.animation;

@override
void initState() {
super.initState();
animation.addListener(handleValueChanged);
animation.addStatusListener(handleStatusChanged);
}

double get colorValue => animation.value * 2;
Color get color => widget.colorTween.lerp(colorValue)!;

void handleValueChanged() {
if (colorValue > maxValue) {
maxValue = colorValue;
widget.colorNotifier.value = color;
}
}

void handleStatusChanged(AnimationStatus status) {
if (status == AnimationStatus.dismissed) {
maxValue = 0;
}
}

@override
void dispose() {
animation.removeListener(handleValueChanged);
animation.removeStatusListener(handleStatusChanged);
super.dispose();
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: animation,
builder: (context, child) {
return Expanded(
child: SizedBox.expand(
child: ColoredBox(color: color),
),
);
},
);
}
}

class Hint extends StatelessWidget {
const Hint({
Key? key,
required this.colorNotifier,
}) : super(key: key);

final ValueNotifier<Color> colorNotifier;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Color>(
valueListenable: colorNotifier,
builder: (context, color, child) {
return Container(width: 8, color: color);
},
);
}
}

class Item extends StatelessWidget {
const Item({
Key? key,
required this.title,
required this.subtitle,
}) : super(key: key);

final String title;
final String subtitle;

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return Padding(
padding: const EdgeInsets.only(left: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: Text(title, style: textTheme.bodyText1)),
Expanded(child: Text(subtitle, style: textTheme.bodyText2)),
],
),
);
}
}
14 changes: 7 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.0"
version: "1.2.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -80,7 +80,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.3"
typed_data:
dependency: transitive
description:
Expand All @@ -155,7 +155,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.22.0"
14 changes: 11 additions & 3 deletions lib/src/action_pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ActionPane extends StatefulWidget {
this.extentRatio = _defaultExtentRatio,
required this.motion,
this.dismissible,
this.dragDismissible = true,
this.openThreshold,
this.closeThreshold,
required this.children,
Expand All @@ -71,6 +72,11 @@ class ActionPane extends StatefulWidget {
/// A widget which controls how the [Slidable] dismisses.
final Widget? dismissible;

/// Indicates whether the [Slidable] can be dismissed by dragging.
///
/// Defaults to true.
final bool dragDismissible;

/// The fraction of the total extent from where the [Slidable] will
/// automatically open when the drag end.
///
Expand Down Expand Up @@ -155,7 +161,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {

@override
double normalizeRatio(double ratio) {
if (widget.dismissible != null) {
if (widget.dismissible != null && widget.dragDismissible) {
return ratio;
}

Expand All @@ -171,7 +177,9 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
final gesture = controller!.endGesture.value;
final position = controller!.animation.value;

if (widget.dismissible != null && position > widget.extentRatio) {
if (widget.dismissible != null &&
widget.dragDismissible &&
position > widget.extentRatio) {
if (controller!.isDismissibleReady) {
controller!.dismissGesture.value = DismissGesture(gesture);
} else {
Expand All @@ -182,7 +190,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
return;
}

if (gesture is OpeningGesture ||
if ((gesture is OpeningGesture && openThreshold <= extentRatio) ||
gesture is StillGesture &&
((gesture.opening && position >= openThreshold) ||
gesture.closing && position > closeThreshold)) {
Expand Down
Loading

0 comments on commit b71fe8a

Please sign in to comment.