Created
December 16, 2020 10:17
-
-
Save Bryanmuloni/b186790b90c94e3d0de4920c31fb1767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'ExpansionTile Collapse', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: TestExpandableView(), | |
); | |
} | |
} | |
class TestExpandableView extends StatefulWidget { | |
@override | |
_TestExpandableViewState createState() => _TestExpandableViewState(); | |
} | |
class _TestExpandableViewState extends State<TestExpandableView> { | |
int _activeMeterIndex; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 400, | |
child: new ListView.builder( | |
shrinkWrap: true, | |
itemCount: 10, | |
itemBuilder: (BuildContext context, int i) { | |
return Card( | |
elevation: 0, | |
// margin: const EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 0.0), | |
child: new ExpansionPanelList( | |
dividerColor: Colors.grey, | |
expansionCallback: (int index, bool status) { | |
setState(() { | |
_activeMeterIndex = _activeMeterIndex == i ? null : i; | |
}); | |
}, | |
children: [ | |
new ExpansionPanel( | |
isExpanded: _activeMeterIndex == i, | |
headerBuilder: (BuildContext context, bool isExpanded) => | |
new Container( | |
padding: const EdgeInsets.only(left: 15.0), | |
alignment: Alignment.centerLeft, | |
child: new Text( | |
'Title-$i', | |
)), | |
body: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text('Details-$i'), | |
], | |
), | |
), | |
], | |
), | |
); | |
}), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment