Skip to content

Commit a2ffe4f

Browse files
author
Sabbir Ahmed
authored
Merge pull request devsonket#571 from tusharhow/patch-3
Refresh Indicator and Expansion Panel Added
2 parents 104112a + 8094bfb commit a2ffe4f

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

data/draft/flutter.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,85 @@ class _MyHomePageState extends State {
506506
}
507507
}
508508
```
509+
## Refresh Indicator
510+
511+
```dart
512+
RefreshIndicator(
513+
strokeWidth: 5,
514+
color: Colors.yellow,
515+
backroundColor: Colors.red,
516+
onRefresh: _refresh,
517+
child: ListView(),
518+
)
519+
```
520+
## Expansion Panel
521+
522+
```dart
523+
// stores ExpansionPanel state information
524+
class Item {
525+
Item({
526+
required this.expandedValue,
527+
required this.headerValue,
528+
this.isExpanded = false,
529+
});
530+
531+
String expandedValue;
532+
String headerValue;
533+
bool isExpanded;
534+
}
535+
536+
List<Item> generateItems(int numberOfItems) {
537+
return List<Item>.generate(numberOfItems, (int index) {
538+
return Item(
539+
headerValue: 'Panel $index',
540+
expandedValue: 'This is item number $index',
541+
);
542+
});
543+
}
544+
545+
// ...
546+
547+
final List<Item> _data = generateItems(8);
548+
549+
@override
550+
Widget build(BuildContext context) {
551+
return SingleChildScrollView(
552+
child: Container(
553+
child: _buildPanel(),
554+
),
555+
);
556+
}
557+
558+
Widget _buildPanel() {
559+
return ExpansionPanelList(
560+
expansionCallback: (int index, bool isExpanded) {
561+
setState(() {
562+
_data[index].isExpanded = !isExpanded;
563+
});
564+
},
565+
children: _data.map<ExpansionPanel>((Item item) {
566+
return ExpansionPanel(
567+
headerBuilder: (BuildContext context, bool isExpanded) {
568+
return ListTile(
569+
title: Text(item.headerValue),
570+
);
571+
},
572+
body: ListTile(
573+
title: Text(item.expandedValue),
574+
subtitle: const Text('To delete this panel, tap the trash can icon'),
575+
trailing: const Icon(Icons.delete),
576+
onTap: () {
577+
setState(() {
578+
_data.removeWhere((Item currentItem) => item == currentItem);
579+
});
580+
}
581+
),
582+
isExpanded: item.isExpanded,
583+
);
584+
}).toList(),
585+
);
586+
}
587+
```
509588

510589
## Radio Button
511590
```dart

0 commit comments

Comments
 (0)