text
stringlengths
1
372
<code_start>
return scrollbar(
thumbVisibility: DeviceType.isDesktop,
controller: _scrollController,
child: GridView.count(
controller: _scrollController,
padding: const EdgeInsets.all(Insets.extraLarge),
childAspectRatio: 1,
crossAxisCount: colCount,
children: listChildren,
),
);
<code_end>
this subtle attention to detail can make your app feel more
comfortable on a given platform.
<topic_end>
<topic_start>
multi-select
dealing with multi-select within a list is another area
with subtle differences across platforms:
<code_start>
static bool get isSpanSelectModifierDown =>
isKeyDown({LogicalKeyboardKey.shiftLeft, LogicalKeyboardKey.shiftRight});
<code_end>
to perform a platform-aware check for control or command,
you can write something like this:
<code_start>
static bool get isMultiSelectModifierDown {
bool isDown = false;
if (platform.ismacos) {
isDown = isKeyDown(
{logicalkeyboardkey.metaleft, LogicalKeyboardKey.metaRight},
);
} else {
isDown = isKeyDown(
{logicalkeyboardkey.controlleft, LogicalKeyboardKey.controlRight},
);
}
return isDown;
}
<code_end>
a final consideration for keyboard users is the select all action.
if you have a large list of items of selectable items,
many of your keyboard users will expect that they can use
Control+A to select all the items.
<topic_end>
<topic_start>
touch devices
on touch devices, multi-selection is typically simplified,
with the expected behavior being similar to having the
isMultiSelectModifier down on the desktop.
you can select or deselect items using a single tap,
and will usually have a button to select all or
clear the current selection.
how you handle multi-selection on different devices depends
on your specific use cases, but the important thing is to
make sure that you’re offering each platform the best
interaction model possible.
<topic_end>
<topic_start>
selectable text
a common expectation on the web (and to a lesser extent desktop)
is that most visible text can be selected with the mouse cursor.
when text is not selectable,
users on the web tend to have an adverse reaction.
luckily, this is easy to support with the SelectableText widget:
<code_start>
return const SelectableText('Select me!');
<code_end>
to support rich text, then use TextSpan:
<code_start>
return const SelectableText.rich(
TextSpan(
children: [
TextSpan(text: 'hello'),
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
);
<code_end>
<topic_end>
<topic_start>
title bars
on modern desktop applications, it’s common to customize
the title bar of your app window, adding a logo for
stronger branding or contextual controls to help save
vertical space in your main UI.
this isn’t supported directly in flutter, but you can use the
bits_dojo package to disable the native title bars,
and replace them with your own.
this package lets you add whatever widgets you want to the
TitleBar because it uses pure flutter widgets under the hood.
this makes it easy to adapt the title bar as you navigate
to different sections of the app.
<topic_end>
<topic_start>
context menus and tooltips
on desktop, there are several interactions that
manifest as a widget shown in an overlay,
but with differences in how they’re triggered, dismissed,