Skip to content

Instantly share code, notes, and snippets.

@burhanrashid52
Created March 20, 2023 06:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save burhanrashid52/ecda974fec5b9532c5a9eeff81f61f03 to your computer and use it in GitHub Desktop.
ExpansionTile Customizations Example
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Expansion Tile Customization'),
),
body: Column(
children: const [
ExpansionTileNoDivider(),
ExpansionTileNoIcon(),
ExpansionTileIconLeft(),
ExpansionTileNoExpand(),
ExpansionTileTextColor(),
],
),
);
}
}
class ExpansionTileTextColor extends StatelessWidget {
const ExpansionTileTextColor({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const ExpansionTile(
title: Text('Change Text Color'),
textColor: Colors.green,
children: _textChildren,
);
}
}
class ExpansionTileNoExpand extends StatelessWidget {
const ExpansionTileNoExpand({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const IgnorePointer(
child: ExpansionTile(
title: Text('No Expansion on Click'),
children: _textChildren,
),
);
}
}
class ExpansionTileIconLeft extends StatelessWidget {
const ExpansionTileIconLeft({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const ExpansionTile(
title: Text('Icon left'),
controlAffinity: ListTileControlAffinity.leading,
children: _textChildren,
);
}
}
class ExpansionTileNoDivider extends StatelessWidget {
const ExpansionTileNoDivider({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(dividerColor: Colors.transparent),
child: const ExpansionTile(
title: Text('No Divider'),
children: _textChildren,
),
);
}
}
class ExpansionTileNoIcon extends StatelessWidget {
const ExpansionTileNoIcon({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const ExpansionTile(
title: Text('No Icon'),
trailing: SizedBox(),
children: _textChildren,
);
}
}
const _textChildren = [
Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'This is the first sentence',
style: TextStyle(fontSize: 18.0),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'This is the second sentence',
style: TextStyle(fontSize: 18.0),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'This is my third last point',
style: TextStyle(fontSize: 18.0),
),
),
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment