text
stringlengths 1
474
|
|---|
it’s the opposite. The confirmation button is
|
placed at the end of the row (right side).This can be easily handled in Flutter using the
|
TextDirection property on Row:
|
<code_start>TextDirection btnDirection =
|
DeviceType.isWindows ? TextDirection.rtl : TextDirection.ltr;
|
return Row(
|
children: [
|
const Spacer(),
|
Row(
|
textDirection: btnDirection,
|
children: [
|
DialogButton(
|
label: 'Cancel',
|
onPressed: () => Navigator.pop(context, false),
|
),
|
DialogButton(
|
label: 'Ok',
|
onPressed: () => Navigator.pop(context, true),
|
),
|
],
|
),
|
],
|
);<code_end>
|
<topic_end>
|
<topic_start>Menu bar
|
Another common pattern on desktop apps is the menu bar.
|
On Windows and Linux, this menu lives as part of the Chrome title bar,
|
whereas on macOS, it’s located along the top of the primary screen.Currently, you can specify custom menu bar entries using
|
a prototype plugin, but it’s expected that this functionality will
|
eventually be integrated into the main SDK.It’s worth mentioning that on Windows and Linux,
|
you can’t combine a custom title bar with a menu bar.
|
When you create a custom title bar,
|
you’re replacing the native one completely,
|
which means you also lose the integrated native menu bar.If you need both a custom title bar and a menu bar,
|
you can achieve that by implementing it in Flutter,
|
similar to a custom context menu.<topic_end>
|
<topic_start>Drag and drop
|
One of the core interactions for both touch-based and
|
pointer-based inputs is drag and drop. Although this
|
interaction is expected for both types of input,
|
there are important differences to think about when
|
it comes to scrolling lists of draggable items.Generally speaking, touch users expect to see drag handles
|
to differentiate draggable areas from scrollable ones,
|
or alternatively, to initiate a drag by using a long
|
press gesture. This is because scrolling and dragging
|
are both sharing a single finger for input.Mouse users have more input options. They can use a wheel
|
or scrollbar to scroll, which generally eliminates the need
|
for dedicated drag handles. If you look at the macOS
|
Finder or Windows Explorer, you’ll see that they work
|
this way: you just select an item and start dragging.In Flutter, you can implement drag and drop in many
|
ways. Discussing specific implementations is outside
|
the scope of this article, but some high level options
|
are:Use the Draggable and DragTarget APIs
|
directly for a custom look and feel.Hook into onPan gesture events,
|
and move an object yourself within a parent Stack.Use one of the pre-made list packages on pub.dev.<topic_end>
|
<topic_start>
|
Educate yourself on basic usability principles
|
Of course, this page doesn’t constitute an exhaustive list
|
of the things you might consider. The more operating systems,
|
form factors, and input devices you support,
|
the more difficult it becomes to spec out every permutation in design.Taking time to learn basic usability principles as a
|
developer empowers you to make better decisions,
|
reduces back-and-forth iterations with design during production,
|
and results in improved productivity with better outcomes.Here are some resources to get you started:
|
<topic_end>
|
<topic_start>Update the UI based on orientation
|
In some situations,
|
you want to update the display of an app when the user
|
rotates the screen from portrait mode to landscape mode. For example,
|
the app might show one item after the next in portrait mode,
|
yet put those same items side-by-side in landscape mode.In Flutter, you can build different layouts depending
|
on a given Orientation.
|
In this example, build a list that displays two columns in
|
portrait mode and three columns in landscape mode using the
|
following steps:<topic_end>
|
<topic_start>
|
1. Build a GridView with two columns
|
First, create a list of items to work with.
|
Rather than using a normal list,
|
create a list that displays items in a grid.
|
For now, create a grid with two columns.
|
<code_start>return GridView.count(
|
// A list with 2 columns
|
crossAxisCount: 2,
|
// ...
|
);<code_end>
|
To learn more about working with GridViews,
|
see the Creating a grid list recipe.<topic_end>
|
<topic_start>
|
2. Use an OrientationBuilder to change the number of columns
|
To determine the app’s current Orientation, use the
|
OrientationBuilder widget.
|
The OrientationBuilder calculates the current Orientation by
|
comparing the width and height available to the parent widget,
|
and rebuilds when the size of the parent changes.Using the Orientation, build a list that displays two columns in portrait
|
mode, or three columns in landscape mode.
|
<code_start>body: OrientationBuilder(
|
builder: (context, orientation) {
|
return GridView.count(
|
// Create a grid with 2 columns in portrait mode,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.