1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6import '../utils.dart';
7import 'use_cases.dart';
8
9class ExpansionTileUseCase extends UseCase {
10 @override
11 String get name => 'ExpansionTile';
12
13 @override
14 String get route => '/expansion-tile';
15
16 @override
17 Widget build(BuildContext context) => const ExpansionTileExample();
18}
19
20class ExpansionTileExample extends StatefulWidget {
21 const ExpansionTileExample({super.key});
22
23 @override
24 State<ExpansionTileExample> createState() => _ExpansionTileExampleState();
25}
26
27class _ExpansionTileExampleState extends State<ExpansionTileExample> {
28 bool _customTileExpanded = false;
29
30 String pageTitle = getUseCaseName(ExpansionTileUseCase());
31
32 @override
33 Widget build(BuildContext context) {
34 return Scaffold(
35 appBar: AppBar(
36 backgroundColor: Theme.of(context).colorScheme.inversePrimary,
37 title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')),
38 ),
39 body: Column(
40 children: <Widget>[
41 const ExpansionTile(
42 title: Text('ExpansionTile 1'),
43 subtitle: Text('Trailing expansion arrow icon'),
44 children: <Widget>[ListTile(title: Text('This is tile number 1'))],
45 ),
46 ExpansionTile(
47 title: const Text('ExpansionTile 2'),
48 subtitle: const Text('Custom expansion arrow icon'),
49 trailing: Icon(
50 _customTileExpanded ? Icons.arrow_drop_down_circle : Icons.arrow_drop_down,
51 ),
52 children: const <Widget>[ListTile(title: Text('This is tile number 2'))],
53 onExpansionChanged: (bool expanded) {
54 setState(() {
55 _customTileExpanded = expanded;
56 });
57 },
58 ),
59 const ExpansionTile(
60 title: Text('ExpansionTile 3'),
61 subtitle: Text('Leading expansion arrow icon'),
62 controlAffinity: ListTileControlAffinity.leading,
63 children: <Widget>[ListTile(title: Text('This is tile number 3'))],
64 ),
65 ],
66 ),
67 );
68 }
69}
70