text stringlengths 1 474 |
|---|
return ElevatedButton( |
onPressed: () { |
developer.log('click'); |
}, |
child: const Text('Button'), |
); |
}<code_end> |
If the Widget doesn’t support event detection, |
wrap the widget in a GestureDetector and pass a function |
to the onTap parameter. |
<code_start>class SampleTapApp extends StatelessWidget { |
const SampleTapApp({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
body: Center( |
child: GestureDetector( |
onTap: () { |
developer.log('tap'); |
}, |
child: const FlutterLogo( |
size: 200, |
), |
), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
Handling other gestures |
Using GestureDetector you can listen |
to a wide range of gestures such as:TappingDouble tappingLong pressingVertical draggingHorizontal draggingThe following example shows a GestureDetector |
that rotates the Flutter logo on a double tap: |
<code_start>class SampleApp extends StatefulWidget { |
const SampleApp({super.key}); |
@override |
State<SampleApp> createState() => _SampleAppState(); |
} |
class _SampleAppState extends State<SampleApp> |
with SingleTickerProviderStateMixin { |
late AnimationController controller; |
late CurvedAnimation curve; |
@override |
void initState() { |
super.initState(); |
controller = AnimationController( |
vsync: this, |
duration: const Duration(milliseconds: 2000), |
); |
curve = CurvedAnimation( |
parent: controller, |
curve: Curves.easeIn, |
); |
} |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
body: Center( |
child: GestureDetector( |
onDoubleTap: () { |
if (controller.isCompleted) { |
controller.reverse(); |
} else { |
controller.forward(); |
} |
}, |
child: RotationTransition( |
turns: curve, |
child: const FlutterLogo( |
size: 200, |
), |
), |
), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
Themes, styles, and media |
Flutter applications are easy to style; you can switch |
between light and dark themes, |
change the style of your text and UI components, |
and more. This section covers aspects of styling your Flutter apps |
and compares how you might do the same in UIKit.<topic_end> |
<topic_start> |
Using a theme |
Out of the box, Flutter comes with a beautiful implementation |
of Material Design, which takes care of a lot of styling and |
theming needs that you would typically do.To take full advantage of Material Components in your app, |
declare a top-level widget, MaterialApp, |
as the entry point to your application. |
MaterialApp is a convenience widget that wraps a number |
of widgets that are commonly required for applications |
implementing Material Design. |
It builds upon a WidgetsApp by adding Material specific functionality.But Flutter is flexible and expressive enough to implement |
any design language. On iOS, you can use the |
Cupertino library to produce an interface that adheres to the |
Human Interface Guidelines. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.