text stringlengths 1 372 |
|---|
this page covers all three categories in detail |
using code snippets to illustrate the concepts. |
if you’d like to see how these concepts come together, |
check out the flokk and folio examples that |
were built using the concepts described here. |
original demo code for adaptive app development techniques from flutter-adaptive-demo. |
<topic_end> |
<topic_start> |
building adaptive layouts |
one of the first things you must consider when writing |
your app for multiple platforms is how to adapt |
it to the various sizes and shapes of the screens that |
it will run on. |
<topic_end> |
<topic_start> |
layout widgets |
if you’ve been building apps or websites, |
you’re probably familiar with creating responsive interfaces. |
luckily for flutter developers, |
there are a large set of widgets to make this easier. |
some of flutter’s most useful layout widgets include: |
single child |
Align—Aligns a child within itself. |
it takes a double value between -1 and 1, |
for both the vertical and horizontal alignment. |
AspectRatio—Attempts to size the |
child to a specific aspect ratio. |
ConstrainedBox—Imposes size constraints on its child, |
offering control over the minimum or maximum size. |
CustomSingleChildLayout—Uses a delegate function |
to position a single child. the delegate can determine |
the layout constraints and positioning for the child. |
expanded and Flexible—Allows a child of a |
row or column to shrink or grow to fill any available space. |
FractionallySizedBox—Sizes its child to a fraction |
of the available space. |
LayoutBuilder—Builds a widget that can reflow |
itself based on its parents size. |
SingleChildScrollView—Adds scrolling to a single child. |
often used with a row or column. |
multichild |
column, row, and Flex—Lays out children |
in a single horizontal or vertical run. |
both column and row extend the flex widget. |
CustomMultiChildLayout—Uses a delegate function to |
position multiple children during the layout phase. |
Flow—Similar to CustomMultiChildLayout, |
but more efficient because it’s performed during the |
paint phase rather than the layout phase. |
ListView, GridView, and |
CustomScrollView—Provides scrollable |
lists of children. |
Stack—Layers and positions multiple children |
relative to the edges of the stack. |
functions similarly to position-fixed in CSS. |
Table—Uses a classic table layout algorithm for |
its children, combining multiple rows and columns. |
Wrap—Displays its children in multiple horizontal |
or vertical runs. |
to see more available widgets and example code, see |
layout widgets. |
<topic_end> |
<topic_start> |
visual density |
different input devices offer various levels of precision, |
which necessitate differently sized hit areas. |
flutter’s VisualDensity class makes it easy to adjust the |
density of your views across the entire application, |
for example, by making a button larger |
(and therefore easier to tap) on a touch device. |
when you change the VisualDensity for your MaterialApp, |
MaterialComponents that support it animate their densities |
to match. by default, both horizontal and vertical densities |
are set to 0.0, but you can set the densities to any negative |
or positive value that you want. by switching between different |
densities, you can easily adjust your UI: |
to set a custom visual density, inject the density into |
your MaterialApp theme: |
<code_start> |
double densityAmt = touchMode ? 0.0 : -1.0; |
VisualDensity density = |
VisualDensity(horizontal: densityAmt, vertical: densityAmt); |
return MaterialApp( |
theme: ThemeData(visualDensity: density), |
home: MainAppScaffold(), |
debugShowCheckedModeBanner: false, |
); |
<code_end> |
to use VisualDensity inside your own views, |
you can look it up: |
<code_start> |
VisualDensity density = Theme.of(context).visualDensity; |
<code_end> |
not only does the container react automatically to changes |
in density, it also animates when it changes. |
this ties together your custom components, |
along with the built-in components, |
for a smooth transition effect across the app. |
as shown, VisualDensity is unit-less, |
so it can mean different things to different views. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.