Created
January 19, 2023 20:23
-
-
Save mihalycsaba/4c1c1649dba596e561d97421dfcd2d32 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(const MaterialApp( | |
title: 'Shopping App', | |
home: MyMainScreen(), | |
)); | |
} | |
List<MyItems> _getMyItems(int index) { | |
return [ | |
MyItems( | |
title: "First Plans", | |
body: MyOwnListView( | |
itemCount: _firstCodeTitles.length, | |
myCodeTitles: _firstCodeTitles, | |
), | |
), | |
MyItems( | |
title: "Second Plans", | |
body: MyOwnListView( | |
itemCount: _secondCodeTitles.length, | |
myCodeTitles: _secondCodeTitles, | |
), | |
), | |
]; | |
} | |
final _firstCodeTitles = [ | |
"Open Account", | |
"Activate USSD", | |
"Deactivate USSD", | |
"Activate Payment", | |
]; | |
final _secondCodeTitles = [ | |
"Customer Care 1", | |
"Customer Care 2", | |
"Customer Care 3", | |
"Customer Care 4", | |
]; | |
class MyMainScreen extends StatefulWidget { | |
const MyMainScreen({ | |
super.key, | |
}); | |
@override | |
State<MyMainScreen> createState() => _MyMainScreenState(); | |
} | |
class _MyMainScreenState extends State<MyMainScreen> { | |
int index = 0; | |
@override | |
Widget build(BuildContext context) { | |
final List<MyItems> items = _getMyItems(index); | |
return Scaffold( | |
appBar: AppBar(), | |
body: ListView( | |
children: [ | |
Column( | |
children: [ | |
ExpansionPanelList.radio( | |
elevation: 6, | |
expandedHeaderPadding: const EdgeInsets.all(8.0), | |
dividerColor: Colors.teal, | |
children: items.map<ExpansionPanelRadio>((MyItems myItems) { | |
return ExpansionPanelRadio( | |
value: myItems.title, | |
canTapOnHeader: true, | |
backgroundColor: const Color(0xffeeeeff), | |
headerBuilder: (context, isExpanded) { | |
return ListTile( | |
title: Text(myItems.title), | |
); | |
}, | |
body: SizedBox( | |
height: MediaQuery.of(context).size.width, | |
child: myItems.body, | |
), | |
); | |
}).toList(), | |
), | |
], | |
), | |
], | |
), | |
); | |
} | |
} | |
class MyItems { | |
MyItems({ | |
required this.title, | |
required this.body, | |
this.isExpanded = false, | |
}); | |
String title; | |
Widget body; | |
bool isExpanded; | |
} | |
class MyOwnListView extends StatelessWidget { | |
const MyOwnListView({ | |
super.key, | |
required this.itemCount, | |
required this.myCodeTitles, | |
}); | |
final int itemCount; | |
final List myCodeTitles; | |
@override | |
Widget build(BuildContext context) { | |
return ListView.separated( | |
itemCount: itemCount, | |
itemBuilder: (context, index) { | |
return Card( | |
child: ListTile( | |
title: Text(myCodeTitles[index]), | |
), | |
); | |
}, | |
separatorBuilder: (context, index) => const Divider(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment