text
stringlengths 1
474
|
---|
); |
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> |
Listviews & adapters |
<topic_end> |
<topic_start> |
What is the alternative to a ListView in Flutter? |
The equivalent to a ListView in Flutter is … a ListView!In an Android ListView, you create an adapter and pass it into the |
ListView, which renders each row with what your adapter returns. However, you |
have to make sure you recycle your rows, otherwise, you get all sorts of crazy |
visual glitches and memory issues.Due to Flutter’s immutable widget pattern, you pass a list of |
widgets to your ListView, and Flutter takes care of making sure |
that scrolling is fast and smooth. |
<code_start>import 'package:flutter/material.dart'; |
void main() { |
runApp(const SampleApp()); |
} |
class SampleApp extends StatelessWidget { |
const SampleApp({super.key}); |
// This widget is the root of your application. |
@override |
Widget build(BuildContext context) { |
return MaterialApp( |
title: 'Sample App', |
theme: ThemeData( |
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), |
), |
home: const SampleAppPage(), |
); |
} |
} |
class SampleAppPage extends StatefulWidget { |
const SampleAppPage({super.key}); |
@override |
State<SampleAppPage> createState() => _SampleAppPageState(); |
} |
class _SampleAppPageState extends State<SampleAppPage> { |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar( |
title: const Text('Sample App'), |
), |
body: ListView(children: _getListData()), |
); |
} |
List<Widget> _getListData() { |
List<Widget> widgets = []; |
for (int i = 0; i < 100; i++) { |
widgets.add(Padding( |
padding: const EdgeInsets.all(10), |
child: Text('Row $i'), |
)); |
} |
return widgets; |
} |
}<code_end> |
<topic_end> |
<topic_start> |
How do I know which list item is clicked on? |
In Android, the ListView has a method to find out which item was clicked, |
‘onItemClickListener’. |
In Flutter, use the touch handling provided by the passed-in widgets. |
<code_start>import 'dart:developer' as developer; |
import 'package:flutter/material.dart'; |
void main() { |
runApp(const SampleApp()); |
} |
class SampleApp extends StatelessWidget { |
const SampleApp({super.key}); |
// This widget is the root of your application. |
@override |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.