grid_list.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import 'package:assets_audio_player/assets_audio_player.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:empty/constants.dart';
  4. class GridListView extends StatefulWidget {
  5. final String type;
  6. final String section;
  7. final String rcmd;
  8. final int size;
  9. final int page;
  10. GridListView(
  11. {Key key, this.type, this.section, this.rcmd, this.size, this.page})
  12. : super(key: key);
  13. @override
  14. _GridListViewState createState() => _GridListViewState();
  15. }
  16. class _GridListViewState extends State<GridListView> {
  17. @override
  18. void initState() {
  19. // TODO: implement initState
  20. super.initState();
  21. albumBloc.fetch(widget.type, widget.section);
  22. if (!isPlaying) panelController.hide();
  23. }
  24. @override
  25. void dispose() {
  26. // TODO: implement dispose
  27. super.dispose();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return OrientationBuilder(
  32. builder: (context, orientation) {
  33. return SingleChildScrollView(
  34. physics: BouncingScrollPhysics(),
  35. child: Column(
  36. children: [
  37. widget.type != '' && widget.section != ''
  38. ? Container(
  39. padding: EdgeInsets.only(
  40. top: 20, bottom: 10, left: 20, right: 20),
  41. child: Stack(
  42. children: [
  43. kHeader[widget.type][widget.section]['icon'] != ""
  44. ? Container(
  45. padding: EdgeInsets.only(top: 10, bottom: 10),
  46. width: 150,
  47. height: 100,
  48. decoration: BoxDecoration(
  49. image: DecorationImage(
  50. alignment: Alignment.bottomCenter,
  51. image: AssetImage('assets/images/' +
  52. kHeader[widget.type]
  53. [widget.section]['icon']),
  54. fit: BoxFit.contain)),
  55. )
  56. : Row(),
  57. Padding(
  58. padding: kHeader[widget.type][widget.section]
  59. ['icon'] !=
  60. ""
  61. ? EdgeInsets.only(left: 120)
  62. : EdgeInsets.only(left: 0),
  63. child: Text(
  64. kHeader[widget.type][widget.section]['detail'],
  65. style: Theme.of(context).textTheme.bodyText1,
  66. ),
  67. ),
  68. ],
  69. ))
  70. : Container(),
  71. StreamBuilder(
  72. stream: albumBloc.albumResult,
  73. builder: (context, snapshot) {
  74. if (!snapshot.hasData) {
  75. return Center(
  76. child: CircularProgressIndicator(),
  77. );
  78. }
  79. return GridView.builder(
  80. shrinkWrap: true,
  81. padding: EdgeInsets.only(
  82. top: 10, left: 10, right: 10, bottom: 250),
  83. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  84. crossAxisCount:
  85. orientation == Orientation.portrait ? 2 : 4,
  86. ),
  87. physics: BouncingScrollPhysics(),
  88. itemCount: snapshot.data.result.length,
  89. itemBuilder: (BuildContext context, int index) {
  90. return GestureDetector(
  91. onTap: () async {
  92. // 개별결재/정기권/쿠폰사용
  93. // snapshot.data.result[index].charge
  94. //print(snapshot.data.result[index].type);
  95. //print(snapshot.data.result[index].section);
  96. //print(snapshot.data.result[index].title);
  97. //print(kUrl + snapshot.data.result[index].poster.filename);
  98. //print(kUrl + snapshot.data.result[index].naration.filename);
  99. //snapshot.data.result[index].charge == ''
  100. // ? Icon(Icons.money, color: Colors.red, size: 30,)
  101. // : Container()
  102. panelController.show();
  103. audios = <Audio>[
  104. Audio.network(
  105. kConfig['content'] +
  106. snapshot
  107. .data.result[index].naration.filename,
  108. metas: Metas(
  109. id: "Online",
  110. title: snapshot.data.result[index].title,
  111. artist: snapshot.data.result[index].section,
  112. album: snapshot.data.result[index].type,
  113. image: MetasImage.network(kConfig['content'] +
  114. snapshot
  115. .data.result[index].poster.filename),
  116. ),
  117. ),
  118. ];
  119. try {
  120. await assetsAudioPlayer.open(
  121. audios[0],
  122. autoStart: true,
  123. showNotification: false,
  124. playInBackground: PlayInBackground.enabled,
  125. audioFocusStrategy: AudioFocusStrategy.request(
  126. resumeAfterInterruption: true,
  127. resumeOthersPlayersAfterDone: true),
  128. headPhoneStrategy:
  129. HeadPhoneStrategy.pauseOnUnplug,
  130. );
  131. setState(() {
  132. isPlaying = true;
  133. });
  134. panelController.open();
  135. } catch (e) {
  136. print(e);
  137. }
  138. },
  139. child: Card(
  140. color: Colors.transparent,
  141. elevation: 5.0,
  142. child: Stack(
  143. fit: StackFit.expand,
  144. children: [
  145. ClipRRect(
  146. borderRadius: BorderRadius.circular(8.0),
  147. child: Image(
  148. image: NetworkImage(
  149. kConfig['content'] +
  150. snapshot.data.result[index].poster
  151. .filename,
  152. scale: 0.85),
  153. fit: BoxFit.fill,
  154. ),
  155. ),
  156. /*
  157. Align(
  158. alignment: Alignment.topRight,
  159. child: Padding(
  160. padding: const EdgeInsets.only(top: 5,right: 10),
  161. child:
  162. snapshot.data.result[index].charge != ''
  163. ? Icon(Icons.enhanced_encryption_outlined, color: Colors.white, size: 20,)
  164. : Container()
  165. ),
  166. ),
  167. */
  168. Align(
  169. alignment: Alignment.bottomCenter,
  170. child: Column(
  171. crossAxisAlignment:
  172. CrossAxisAlignment.stretch,
  173. verticalDirection: VerticalDirection.up,
  174. children: <Widget>[
  175. Container(
  176. padding: EdgeInsets.all(10),
  177. color: Colors.black.withOpacity(.4),
  178. child: Text(
  179. snapshot.data.result[index].title,
  180. overflow: TextOverflow.ellipsis,
  181. style: Theme.of(context)
  182. .textTheme
  183. .bodyText1,
  184. ),
  185. ),
  186. ],
  187. )),
  188. ],
  189. ),
  190. ),
  191. );
  192. });
  193. },
  194. ),
  195. ],
  196. ),
  197. );
  198. },
  199. );
  200. }
  201. }