Last active
November 23, 2019 16:58
-
-
Save raviganwal/94b3b2d2e129239f34b912ef202b6641 to your computer and use it in GitHub Desktop.
FoldingCellWithModel
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'; | |
import 'package:folding_cell/folding_cell.dart'; | |
void main() => runApp(MaterialApp( | |
home: SafeArea( | |
child: Scaffold(body: Material(child: FoldingCellListViewDemo()))))); | |
class DemoModel { | |
String title, subtitle; | |
DemoModel(this.title, this.subtitle); | |
} | |
/// Example 2 folding cell inside [ListView] | |
class FoldingCellListViewDemo extends StatelessWidget { | |
final List<DemoModel> txtList = [ | |
DemoModel('title 1', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry. Lorem Ipsum has been the industry. Lorem Ipsum has been the industry.'), | |
DemoModel('title 2', 'subtitle 2'), | |
DemoModel('title 3', 'subtitle 3'), | |
DemoModel('title 4', 'subtitle 4'), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Color(0xFF2e282a), | |
child: ListView.builder( | |
itemCount: txtList.length, | |
itemBuilder: (context, index) { | |
DemoModel model = txtList[index]; | |
return SimpleFoldingCell( | |
frontWidget: _buildFrontWidget(model), | |
innerTopWidget: _buildInnerTopWidget(model), | |
innerBottomWidget: _buildInnerBottomWidget(index), | |
cellSize: Size(MediaQuery.of(context).size.width, 125), | |
padding: EdgeInsets.all(15), | |
animationDuration: Duration(milliseconds: 300), | |
borderRadius: 10, | |
onOpen: () => print('$index cell opened'), | |
onClose: () => print('$index cell closed')); | |
}), | |
); | |
} | |
Widget _buildFrontWidget(DemoModel model) { | |
return Builder( | |
builder: (BuildContext context) { | |
return Container( | |
color: Color(0xFFffcd3c), | |
alignment: Alignment.center, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text("${model.title}", | |
style: TextStyle( | |
color: Color(0xFF2e282a), | |
fontFamily: 'OpenSans', | |
fontSize: 20.0, | |
fontWeight: FontWeight.w800)), | |
FlatButton( | |
onPressed: () { | |
SimpleFoldingCellState foldingCellState = | |
context.ancestorStateOfType( | |
TypeMatcher<SimpleFoldingCellState>()); | |
foldingCellState?.toggleFold(); | |
}, | |
child: Text( | |
"Open", | |
), | |
textColor: Colors.white, | |
color: Colors.indigoAccent, | |
splashColor: Colors.white.withOpacity(0.5), | |
) | |
], | |
)); | |
}, | |
); | |
} | |
Widget _buildInnerTopWidget(DemoModel model) { | |
return Container( | |
color: Color(0xFFff9234), | |
alignment: Alignment.center, | |
child: Text("${model.subtitle}", | |
style: TextStyle( | |
color: Color(0xFF2e282a), | |
fontFamily: 'OpenSans', | |
fontSize: 14.0, | |
fontWeight: FontWeight.w400))); | |
} | |
Widget _buildInnerBottomWidget(int index) { | |
return Builder(builder: (context) { | |
return Container( | |
color: Color(0xFFecf2f9), | |
alignment: Alignment.bottomCenter, | |
child: Padding( | |
padding: EdgeInsets.only(bottom: 10), | |
child: FlatButton( | |
onPressed: () { | |
SimpleFoldingCellState foldingCellState = context | |
.ancestorStateOfType(TypeMatcher<SimpleFoldingCellState>()); | |
foldingCellState?.toggleFold(); | |
}, | |
child: Text( | |
"Close", | |
), | |
textColor: Colors.white, | |
color: Colors.indigoAccent, | |
splashColor: Colors.white.withOpacity(0.5), | |
), | |
), | |
); | |
}); | |
} | |
} |
Repo link is broken, try to create repo of your complete code so I can run that in one go only
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/ABINASH56/ghost-app PLEASE CHECK THIS LINK