Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion example/lib/file_asset_paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ enum FileAssetPaths {
),
shrinkAndFlexScreen(
'lib/screens/shrink_and_flex/shrink_and_flex_example_screen.dart',
);
),
cascadingDeltaScreen(
'lib/screens/cascading_delta/cascading_delta_screen.dart',
),
;

const FileAssetPaths(this.path);
final String path;
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:example/screens/basic/basic_example_screen.dart';
import 'package:example/screens/cascading_delta/cascading_delta_screen.dart';
import 'package:example/screens/controller_listen/controller_listen_example_screen.dart';
import 'package:example/screens/controller_set_sizes/controller_set_sizes_example_screen.dart';
import 'package:example/screens/divider/custom_divider_example_screen.dart';
Expand Down Expand Up @@ -31,6 +32,7 @@ class ExampleApp extends StatelessWidget {
'shrink': (context) => const ShrinkAndFlexExampleScreen(),
'future-builder-shrink': (context) =>
const FutureBuilderShrinkExampleScreen(),
'cascading-delta': (context) => const CascadingDeltaScreen(),
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:example/widgets/help_dialog.dart';
import 'package:flutter/material.dart';

class CascadingDeltaHelpDialog extends StatelessWidget {
const CascadingDeltaHelpDialog._({super.key});

static void show({
required BuildContext context,
}) {
HelpDialog.show(
context: context,
child: const CascadingDeltaHelpDialog._(
key: Key('CascadingDeltaHelpDialog'),
),
);
}

@override
Widget build(BuildContext context) {
return const HelpDialog(
title: 'About this example',
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'In this example, there are four children, each with a minimum width of 50 pixels.',
),
SizedBox(height: 12),
Text.rich(TextSpan(children: [
TextSpan(text: 'Use the '),
TextSpan(
text: 'Cascade',
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: ' switch to enable/disable the '),
TextSpan(
text: 'cascadeNegativeDelta',
style: TextStyle(
fontFamily: 'Monospace',
color: Colors.blueGrey,
),
),
TextSpan(text: ' flag in the ResizableContainer.'),
])),
SizedBox(height: 12),
Text.rich(TextSpan(children: [
TextSpan(text: 'With the switch '),
TextSpan(
text: 'enabled',
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(
text:
', reducing the size of a child beyond its bound will "cascade" the change to its sibling(s).',
),
TextSpan(text: ' With the switch '),
TextSpan(
text: 'disabled',
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(
text:
', reducing the size of a child beyond its bound will have no effect (default behavior).',
),
])),
],
),
);
}
}
85 changes: 85 additions & 0 deletions example/lib/screens/cascading_delta/cascading_delta_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:example/file_asset_paths.dart';
import 'package:example/screens/cascading_delta/cascading_delta_help_dialog.dart';
import 'package:example/widgets/code_view_dialog.dart';
import 'package:example/widgets/nav_drawer.dart';
import 'package:example/widgets/size_label.dart';
import 'package:flutter/material.dart';
import 'package:flutter_resizable_container/flutter_resizable_container.dart';

class CascadingDeltaScreen extends StatefulWidget {
const CascadingDeltaScreen({super.key});

@override
State<CascadingDeltaScreen> createState() => _CascadingDeltaScreenState();
}

class _CascadingDeltaScreenState extends State<CascadingDeltaScreen> {
var cascade = false;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cascading delta example'),
actions: [
Row(
children: [
const Text('Cascade'),
const SizedBox(width: 8),
Switch(
value: cascade,
onChanged: (cascade) => setState(() => this.cascade = cascade),
),
],
),
IconButton(
icon: const Icon(Icons.help_center),
onPressed: () => CascadingDeltaHelpDialog.show(context: context),
),
IconButton(
icon: const Icon(Icons.code),
onPressed: () => CodeViewDialog.show(
context: context,
filePath: FileAssetPaths.cascadingDeltaScreen,
),
),
],
),
drawer: const NavDrawer(),
body: ResizableContainer(
direction: Axis.horizontal,
cascadeNegativeDelta: cascade,
children: [
ResizableChild(
size: const ResizableSize.expand(min: 50),
child: ColoredBox(
color: Theme.of(context).colorScheme.primaryContainer,
child: const SizeLabel(),
),
),
ResizableChild(
size: const ResizableSize.expand(min: 50),
child: ColoredBox(
color: Theme.of(context).colorScheme.secondaryContainer,
child: const SizeLabel(),
),
),
ResizableChild(
size: const ResizableSize.expand(min: 50),
child: ColoredBox(
color: Theme.of(context).colorScheme.primaryContainer,
child: const SizeLabel(),
),
),
ResizableChild(
size: const ResizableSize.expand(min: 50),
child: ColoredBox(
color: Theme.of(context).colorScheme.secondaryContainer,
child: const SizeLabel(),
),
),
],
),
);
}
}
5 changes: 5 additions & 0 deletions example/lib/widgets/nav_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class NavDrawer extends StatelessWidget {
onTap: () => Navigator.of(context)
.pushReplacementNamed('future-builder-shrink'),
),
ListTile(
title: const Text('Cascading Delta Example'),
onTap: () =>
Navigator.of(context).pushReplacementNamed('cascading-delta'),
),
const SizedBox(height: 15),
const NavSectionHeader(title: 'Controller Examples'),
ListTile(
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
version: "2.1.3"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -320,10 +320,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: dc6ecaa00a7c708e5b4d10ee7bec8c270e9276dfcab1783f57e9962d7884305f
sha256: daf97c9d80197ed7b619040e86c8ab9a9dad285e7671ee7390f9180cc828a51e
url: "https://pub.dev"
source: hosted
version: "5.12.0"
version: "5.10.1"
sdks:
dart: ">=3.7.0 <4.0.0"
dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.22.0"
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ flutter:
- lib/screens/pixels/pixels_example_screen.dart
- lib/screens/ratio/ratio_example_screen.dart
- lib/screens/shrink_and_flex/shrink_and_flex_example_screen.dart
- lib/screens/cascading_delta/cascading_delta_screen.dart

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down
25 changes: 17 additions & 8 deletions lib/src/resizable_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ import 'package:flutter_resizable_container/src/resizable_controller.dart';
class ResizableContainer extends StatefulWidget {
/// Creates a new [ResizableContainer] with the given [direction] and list
/// of [children] Widgets.
///
/// The sum of the [children]'s starting ratios must be equal to 1.0.
const ResizableContainer({
super.key,
required this.children,
required this.direction,
this.controller,
this.cascadeNegativeDelta = false,
});

/// A list of resizable [ResizableChild] containing the child [Widget]s and
/// A list of [ResizableChild] containing the child [Widget]s and
/// their sizing configuration.
final List<ResizableChild> children;

Expand All @@ -34,6 +33,10 @@ class ResizableContainer extends StatefulWidget {
/// The direction along which the child widgets will be laid and resized.
final Axis direction;

/// When enabled, reducing the size of a child beyond its lower bound will reduce the
/// size of its sibling(s). Defaults to `false`.
final bool cascadeNegativeDelta;

@override
State<ResizableContainer> createState() => _ResizableContainerState();
}
Expand All @@ -48,19 +51,25 @@ class _ResizableContainerState extends State<ResizableContainer> {
super.initState();

manager.initChildren(widget.children);
manager.setCascadeNegativeDelta(widget.cascadeNegativeDelta);
}

@override
void didUpdateWidget(covariant ResizableContainer oldWidget) {
final childrenChanged = !listEquals(oldWidget.children, widget.children);
final directionChanged = oldWidget.direction != widget.direction;
final hasChanges = childrenChanged || directionChanged;
final cascadeChanged =
oldWidget.cascadeNegativeDelta != widget.cascadeNegativeDelta;

if (childrenChanged) {
controller.setChildren(widget.children);
}

if (hasChanges) {
if (childrenChanged) {
controller.setChildren(widget.children);
}
if (cascadeChanged) {
manager.setCascadeNegativeDelta(widget.cascadeNegativeDelta);
}

if (childrenChanged || directionChanged) {
manager.setNeedsLayout();
}

Expand Down
Loading