Skip to content

Add TwoPane widget#92910

Closed
andreidiaconu wants to merge 4 commits intoflutter:masterfrom
andreidiaconu:foldable_support_twopane
Closed

Add TwoPane widget#92910
andreidiaconu wants to merge 4 commits intoflutter:masterfrom
andreidiaconu:foldable_support_twopane

Conversation

@andreidiaconu
Copy link
Contributor

@andreidiaconu andreidiaconu commented Nov 2, 2021

This PR adds the TwoPane widget which helps with creating layouts on foldable and large screen devices. The goal is to provide an easy way to write two-pane layouts that show less or more content according to available space, while at the same time reacting to existing display features on the device.

Here is an image of what the simplest usage of the widget will produce on 3 different platforms and available screen space:

Screenshot 2021-11-02 at 14 23 37

This is split from a larger PR for foldable support in order to make it easier to review (#77156).

Issues that will be fixed by this PR:

Depends on:

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Nov 2, 2021
@google-cla google-cla bot added the cla: yes label Nov 2, 2021
@HansMuller HansMuller requested a review from goderbauer November 6, 2021 00:03
@Piinks Piinks self-requested a review November 11, 2021 21:59
@Piinks Piinks added c: new feature Nothing broken; request for a new capability a: layout SystemChrome and Framework's Layout Issues labels Nov 11, 2021
@Piinks
Copy link
Contributor

Piinks commented Nov 30, 2021

cc @HansMuller, I mentioned this in a meeting today

@PieterAelse
Copy link

PieterAelse commented Feb 11, 2022

@andreidiaconu I've watched your talk at Flutter Vikings, which was very informative and well presented!, and tried out TwoPane today. Was a bit surprised by the easiness (simple but flexible API) and results/benefit one would get from it. So I have to say; nice work and thanks! 😄

@andreidiaconu andreidiaconu force-pushed the foldable_support_twopane branch from 30c70f5 to 4acaa23 Compare February 17, 2022 19:21
@skia-gold
Copy link

Gold has detected about 38 new digest(s) on patchset 15.
View them at https://flutter-gold.skia.org/cl/github/92910

@andreidiaconu andreidiaconu force-pushed the foldable_support_twopane branch from 4acaa23 to b738bd3 Compare February 17, 2022 19:30
@andreidiaconu andreidiaconu marked this pull request as ready for review February 17, 2022 20:06
@andreidiaconu
Copy link
Contributor Author

@Piinks This is also ready for review now. Thank you

@andreidiaconu
Copy link
Contributor Author

@PieterAelse Thank you for having a look at this. I refactored most of what you saw last time as I was not happy with a number of things. Thank you

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this may be better served as a package on pub.dev, WDYT @andreidiaconu?

import 'framework.dart';
import 'media_query.dart';

/// A widget that positions two panes side by side on uninterrupted screens or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not appear true based on the mobile phone image in OP.

Comment on lines +19 to +21
/// * it obstructs the screen, meaning the area it occupies is not 0. Display
/// features of type [DisplayFeatureType.fold] can have height 0 or width 0
/// and not be obstructing the screen.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the TwoPane will not work with devices that fold without a hinge?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means it works, but the separation between the two panes does not need to coincide with the folding feature since the screen is continuous.

Comment on lines +39 to +48
/// On screens that have multiple separating [DisplayFeature]s, [textDirection]
/// and [verticalDirection] parameters are used to decide which one is first and
/// is used as a separator between the two panes. If both horizontal and
/// vertical [DisplayFeature]s exist, the [direction] parameter is used to
/// ignore the [DisplayFeature]s that would conflict with it.
///
/// This widget is similar to [Flex] and also takes [textDirection] and
/// [verticalDirection] parameters, which are used for deciding in what order
/// the panes are laid out (e.g [TextDirection.ltr] would position [startPane]
/// on the left and [endPane] on the right).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two paragraphs seem redundant

Comment on lines +107 to +108
/// If [panePriority] is [TwoPanePriority.start], this is the only pane
/// visible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? What happens to the second pane then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TwoPanePriority is start or end, then only one pane is part of the tree. In this case endPane is not part of the tree.

Comment on lines +127 to +128
/// If [panePriority] is [TwoPanePriority.end], this is the only pane
/// visible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, but reversed for pane. :)

/// [DisplayFeature], in which case each pane takes over one sub-screen.
final double paneProportion;

/// Same as [Flex.textDirection].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could template some docs from Flex for these following parameters and use a macro. Just saying they are the same isn't super helpful if folks don't know what they are.

/// measures the distance between TwoPane and the ambient MediaQuery.
///
/// Defaults to [EdgeInsets.zero].
final EdgeInsets inset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be padding to remain consistent with the framework

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it was padding but at the last minute I found it confusing and renamed it. Will change back 👍

/// Returns only the display features that separate the screen into
/// sub-screens.
///
/// A [DisplayFeature] separates the screen into sub-screens when both these
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to leave out foldable devices with a continuous screen, but I may be misunderstanding

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the screen is continuous the two panes don't need to split on the folding feature, so they are free to take the proportions provided to the widget, the same way they would on a tablet or larger screen.

@andreidiaconu
Copy link
Contributor Author

I am wondering if this may be better served as a package on pub.dev, WDYT @andreidiaconu?

Our hope was to have everything related to foldable support in the framework in order to make it a seamless dev experience - but TwoPane is not used in any other part of the framework, so I understand the advantages of moving it to a separate package.

@goderbauer
Copy link
Member

I agree with @Piinks that this widget would be better suited in a separate package.

@andreidiaconu
Copy link
Contributor Author

Ok, closing this and moving the widget to a separate package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: layout SystemChrome and Framework's Layout Issues a: tests "flutter test", flutter_test, or one of our tests c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants