text
stringlengths
1
372
elevation: 20,
child: ListTile(
leading: const Icon(Icons.change_history),
title: const Text('Screen2'),
onTap: () {
Navigator.of(context).pushNamed('/b');
},
),
);
}
<code_end>
the scaffold widget also includes an AppBar widget that automatically
displays an appropriate IconButton to show the drawer when a drawer is
available in the scaffold. the scaffold automatically handles the
edge-swipe gesture to show the drawer.
<code_start>
@override
widget build(BuildContext context) {
return scaffold(
drawer: drawer(
elevation: 20,
child: ListTile(
leading: const Icon(Icons.change_history),
title: const Text('Screen2'),
onTap: () {
Navigator.of(context).pushNamed('/b');
},
),
),
appBar: AppBar(title: const Text('Home')),
body: container(),
);
}
<code_end>
<topic_end>
<topic_start>
gesture detection and touch event handling
to listen for and respond to gestures,
flutter supports taps, drags, and scaling.
the gesture system in flutter has two separate layers.
the first layer includes raw pointer events,
which describe the location and movement of pointers,
(such as touches, mice, and styli movements), across the screen.
the second layer includes gestures,
which describe semantic actions
that consist of one or more pointer movements.
<topic_end>
<topic_start>
how do i add a click or press listeners to a widget?
in react native, listeners are added to components
using PanResponder or the touchable components.
for more complex gestures and combining several touches into
a single gesture, PanResponder is used.
in flutter, to add a click (or press) listener to a widget,
use a button or a touchable widget that has an onPress: field.
or, add gesture detection to any widget by wrapping it
in a GestureDetector.
<code_start>
@override
widget build(BuildContext context) {
return GestureDetector(
child: scaffold(
appBar: AppBar(title: const Text('Gestures')),
body: const center(
child: column(
mainAxisAlignment: MainAxisAlignment.center,
children: <widget>[
Text('Tap, long press, swipe horizontally or vertically'),
],
)),
),
onTap: () {
print('Tapped');
},
onLongPress: () {
print('Long pressed');
},
onVerticalDragEnd: (value) {
print('Swiped vertically');
},
onHorizontalDragEnd: (value) {
print('Swiped horizontally');
},
);
}
<code_end>
for more information, including a list of
flutter GestureDetector callbacks,
see the GestureDetector class.
<topic_end>
<topic_start>
making HTTP network requests
fetching data from the internet is common for most apps. and in flutter,
the http package provides the simplest way to fetch data from the internet.
<topic_end>
<topic_start>
how do i fetch data from API calls?
react native provides the fetch API for networking—you make a fetch request
and then receive the response to get the data.
flutter uses the http package.