text
stringlengths 1
372
|
---|
Icon(CupertinoIcons.arrow_down_square), |
Icon(CupertinoIcons.arrow_up_square), |
Text('Row 2'), |
Icon(CupertinoIcons.arrow_down_square), |
Icon(CupertinoIcons.arrow_up_square), |
]; |
class HomePage extends StatelessWidget { |
const HomePage({super.key}); |
@override |
widget build(BuildContext context) { |
return scaffold( |
body: GridView.builder( |
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( |
crossAxisCount: 3, |
mainAxisExtent: 40, |
), |
itemCount: widgets.length, |
itemBuilder: (context, index) => widgets[index], |
), |
); |
} |
} |
<code_end> |
the SliverGridDelegateWithFixedCrossAxisCount delegate determines |
various parameters that the grid uses to lay out its components. |
this includes crossAxisCount that dictates the number of items |
displayed on each row. |
how SwiftUI’s grid and flutter’s GridView differ in that grid |
requires GridRow. GridView uses the delegate to decide how the |
grid should lay out its components. |
<topic_end> |
<topic_start> |
creating a scroll view |
in SwiftUI, you use ScrollView to create custom scrolling |
components. |
the following example displays a series of PersonView instances |
in a scrollable fashion. |
to create a scrolling view, flutter uses SingleChildScrollView. |
in the following example, the function mockPerson mocks instances |
of the person class to create the custom PersonView widget. |
<code_start> |
SingleChildScrollView( |
child: column( |
children: mockPersons |
.map( |
(person) => PersonView( |
person: person, |
), |
) |
.tolist(), |
), |
), |
<code_end> |
<topic_end> |
<topic_start> |
responsive and adaptive design |
in SwiftUI, you use GeometryReader to create relative view sizes. |
for example, you could: |
you can also see if the size class has .regular or .compact |
using horizontalSizeClass. |
to create relative views in flutter, you can use one of two options: |
to learn more, check out creating responsive and adaptive apps. |
<topic_end> |
<topic_start> |
managing state |
in SwiftUI, you use the @state property wrapper to represent the |
internal state of a SwiftUI view. |
SwiftUI also includes several options for more complex state |
management such as the ObservableObject protocol. |
flutter manages local state using a StatefulWidget. |
implement a stateful widget with the following two classes: |
the state object stores the widget’s state. |
to change a widget’s state, call setState() from the state subclass |
to tell the framework to redraw the widget. |
the following example shows a part of a counter app: |
<code_start> |
class MyHomePage extends StatefulWidget { |
const MyHomePage({super.key}); |
@override |
State<MyHomePage> createState() => _MyHomePageState(); |
} |
class _MyHomePageState extends State<MyHomePage> { |
int _counter = 0; |
@override |
widget build(BuildContext context) { |
return scaffold( |
body: center( |
child: column( |
mainAxisAlignment: MainAxisAlignment.center, |
children: [ |
text('$_counter'), |
TextButton( |
onPressed: () => setState(() { |
_counter++; |
}), |
child: const text('+'), |
), |
], |
), |
), |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.