blob: c746378218a2ef37cfd08cb870cbe002ca90fd01 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for [ListTile.selected].
import 'package:flutter/material.dart';
void main() => runApp(const ListTileApp());
class ListTileApp extends StatelessWidget {
const ListTileApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: LisTileExample(),
);
}
}
class LisTileExample extends StatefulWidget {
const LisTileExample({super.key});
@override
State<LisTileExample> createState() => _LisTileExampleState();
}
class _LisTileExampleState extends State<LisTileExample> {
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Custom List Item Sample')),
body: ListView.builder(
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Item $index'),
selected: index == _selectedIndex,
onTap: () {
setState(() {
_selectedIndex = index;
});
},
);
},
),
);
}
}