text
stringlengths 1
474
|
|---|
super.initState();
|
controller = AnimationController(
|
duration: const Duration(milliseconds: 2000),
|
vsync: this,
|
);
|
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 and adapters
|
<topic_end>
|
<topic_start>
|
What is the equivalent to a ListView in Flutter?
|
The equivalent to a ListView in Flutter is … a ListView!In a Xamarin.Forms ListView, you create a ViewCell
|
and possibly a DataTemplateSelectorand pass it into the ListView,
|
which renders each row with what your
|
DataTemplateSelector or ViewCell returns.
|
However, you often have to make sure you turn on Cell Recycling
|
otherwise you will run into memory issues and slow scrolling speeds.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 {
|
/// This widget is the root of your application.
|
const SampleApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'Sample App',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
class SampleAppPage extends StatelessWidget {
|
const SampleAppPage({super.key});
|
List<Widget> _getListData() {
|
return List<Widget>.generate(
|
100,
|
(index) => Padding(
|
padding: const EdgeInsets.all(10),
|
child: Text('Row $index'),
|
),
|
);
|
}
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(title: const Text('Sample App')),
|
body: ListView(children: _getListData()),
|
);
|
}
|
}<code_end>
|
<topic_end>
|
<topic_start>
|
How do I know which list item has been clicked?
|
In Xamarin.Forms, the ListView has an ItemTapped method
|
to find out which item was clicked.
|
There are many other techniques you might have used
|
such as checking when SelectedItem or EventToCommand
|
behaviors change.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 {
|
// This widget is the root of your application.
|
const SampleApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'Sample App',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.