text stringlengths 1 372 |
|---|
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, |
// or 3 columns in landscape mode. |
crossAxisCount: orientation == orientation.portrait ? 2 : 3, |
); |
}, |
), |
<code_end> |
info note |
if you’re interested in the orientation of the screen, |
rather than the amount of space available to the parent, |
use MediaQuery.of(context).orientation instead of an |
OrientationBuilder widget. |
<topic_end> |
<topic_start> |
interactive example |
<code_start> |
import 'package:flutter/material.dart'; |
void main() { |
runApp(const MyApp()); |
} |
class MyApp extends StatelessWidget { |
const MyApp({super.key}); |
@override |
widget build(BuildContext context) { |
const appTitle = 'orientation demo'; |
return const MaterialApp( |
title: appTitle, |
home: OrientationList( |
title: appTitle, |
), |
); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.