main_screen.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import 'package:flutter/material.dart';
  2. import 'package:double_back_to_close/double_back_to_close.dart';
  3. import 'package:convex_bottom_bar/convex_bottom_bar.dart';
  4. import 'package:sliding_up_panel/sliding_up_panel.dart';
  5. import 'package:assets_audio_player/assets_audio_player.dart';
  6. import 'package:empty/components/background.dart';
  7. import 'package:empty/components/playing_control.dart';
  8. import 'package:empty/components/position_seek_widget.dart';
  9. import 'package:empty/screens/home_screen.dart';
  10. import 'package:empty/screens/body_screen.dart';
  11. import 'package:empty/screens/mind_screen.dart';
  12. import 'package:empty/constants.dart';
  13. class MainScreen extends StatefulWidget {
  14. @override
  15. _MainScreenState createState() => _MainScreenState();
  16. }
  17. class _MainScreenState extends State<MainScreen> {
  18. TabController _tabController;
  19. int _selectedPage = 1;
  20. final double _initFabHeight = 120.0;
  21. double _fabHeight;
  22. double _panelHeightOpen;
  23. double _panelHeightClosed = 95.0;
  24. bool _panelState = false;
  25. Audio find(List<Audio> source, String fromPath) {
  26. return source.firstWhere((element) => element.path == fromPath);
  27. }
  28. Widget _pageOptions(int index) {
  29. switch (index) {
  30. case 0:
  31. return BodyScreen();
  32. break;
  33. case 1:
  34. return HomeScreen();
  35. break;
  36. case 2:
  37. return MindScreen();
  38. break;
  39. }
  40. }
  41. @override
  42. void initState() {
  43. // TODO: implement initState
  44. super.initState();
  45. /*
  46. subscriptions.add(assetsAudioPlayer.playlistAudioFinished.listen((data) {
  47. // print("playlistAudioFinished : $data");
  48. panelController.hide();
  49. }));
  50. subscriptions.add(assetsAudioPlayer.audioSessionId.listen((sessionId) {
  51. print("audioSessionId : $sessionId");
  52. }));
  53. subscriptions.add(assetsAudioPlayer.current.listen((data) {
  54. print("current : $data");
  55. }));
  56. subscriptions.add(assetsAudioPlayer.onReadyToPlay.listen((audio) {
  57. print("onReadyToPlay : $audio");
  58. }));
  59. subscriptions.add(assetsAudioPlayer.isBuffering.listen((isBuffering) {
  60. print("isBuffering : $isBuffering");
  61. }));
  62. subscriptions.add(assetsAudioPlayer.playerState.listen((playerState) {
  63. print("playerState : $playerState");
  64. }));
  65. subscriptions.add(assetsAudioPlayer.isPlaying.listen((isplaying) {
  66. print("isplaying : $isplaying");
  67. }));
  68. */
  69. subscriptions
  70. .add(AssetsAudioPlayer.addNotificationOpenAction((notification) {
  71. return false;
  72. }));
  73. _fabHeight = _initFabHeight;
  74. }
  75. @override
  76. void dispose() {
  77. // TODO: implement dispose
  78. super.dispose();
  79. assetsAudioPlayer.dispose();
  80. }
  81. @override
  82. Widget build(BuildContext context) {
  83. _panelHeightOpen = MediaQuery.of(context).size.height * .90;
  84. return DoubleBack(
  85. message: "'뒤로' 버튼을 한번더 누르시면 종료됩니다.",
  86. child: Background(
  87. image: Container(
  88. height: double.infinity,
  89. width: double.infinity,
  90. decoration: BoxDecoration(
  91. image: DecorationImage(
  92. image: AssetImage('assets/images/background_body.png'),
  93. fit: BoxFit.cover)),
  94. ),
  95. child: Scaffold(
  96. backgroundColor: Colors.transparent,
  97. // extendBodyBehindAppBar: true,
  98. appBar: AppBar(
  99. title: Text('EMPTY'),
  100. centerTitle: true,
  101. backgroundColor: Color.fromRGBO(0, 41, 91, 0.5),
  102. elevation: 0.0,
  103. leading: IconButton(
  104. icon: Icon(Icons.help_outline),
  105. onPressed: () {
  106. assetsAudioPlayer.stop();
  107. panelController.hide();
  108. Navigator.pushNamed(context, '/guide');
  109. },
  110. ),
  111. actions: [
  112. IconButton(
  113. icon: Icon(Icons.menu),
  114. onPressed: () {
  115. Navigator.pushNamed(context, '/config');
  116. }),
  117. ],
  118. ),
  119. bottomNavigationBar: ConvexAppBar(
  120. controller: _tabController,
  121. height: 60,
  122. curveSize: 100,
  123. activeColor: Colors.blue[200],
  124. // style: TabStyle.fixedCircle,
  125. items: [
  126. TabItem(icon: Icons.accessibility, title: 'BODY'),
  127. TabItem(icon: Icons.home, title: 'HOME'),
  128. TabItem(icon: Icons.favorite, title: 'MIND'),
  129. ],
  130. initialActiveIndex: _selectedPage,
  131. onTap: (int i) {
  132. setState(() {
  133. _selectedPage = i;
  134. });
  135. },
  136. gradient: LinearGradient(
  137. begin: Alignment.topCenter,
  138. end: Alignment.bottomCenter,
  139. colors: [Color(0xff0b3762), Color(0xff002e5b)]),
  140. ),
  141. body: Stack(
  142. alignment: Alignment.topCenter,
  143. children: [
  144. SlidingUpPanel(
  145. maxHeight: _panelHeightOpen,
  146. minHeight: _panelHeightClosed,
  147. backdropEnabled: true,
  148. parallaxEnabled: true,
  149. color: Colors.transparent,
  150. controller: panelController,
  151. body: _pageOptions(_selectedPage),
  152. collapsed: Container(
  153. padding: EdgeInsets.only(top: 0),
  154. decoration: BoxDecoration(
  155. color: Colors.black.withOpacity(0.9),
  156. ),
  157. child: assetsAudioPlayer.builderCurrent(
  158. builder: (context, playing) {
  159. if (playing == null) {
  160. return SizedBox();
  161. }
  162. return Row(
  163. mainAxisSize: MainAxisSize.max,
  164. crossAxisAlignment: CrossAxisAlignment.stretch,
  165. children: [
  166. Expanded(
  167. child: assetsAudioPlayer
  168. .builderRealtimePlayingInfos(
  169. builder: (context, infos) {
  170. if (infos == null) {
  171. return SizedBox();
  172. }
  173. return PositionSeekWidget(
  174. currentPosition: infos.currentPosition,
  175. duration: infos.duration,
  176. seekTo: (to) {
  177. assetsAudioPlayer.seek(to);
  178. },
  179. );
  180. }),
  181. ),
  182. Container(
  183. child: assetsAudioPlayer.builderLoopMode(
  184. builder: (context, loopMode) {
  185. return PlayerBuilder.isPlaying(
  186. player: assetsAudioPlayer,
  187. builder: (context, isPlaying) {
  188. return PlayingControls(
  189. loopMode: loopMode,
  190. isPlaying: isPlaying,
  191. isPlaylist: true,
  192. onStop: () {
  193. assetsAudioPlayer.stop();
  194. panelController.hide();
  195. },
  196. toggleLoop: () {
  197. assetsAudioPlayer.toggleLoop();
  198. },
  199. onPlay: () {
  200. assetsAudioPlayer.playOrPause();
  201. },
  202. onNext: () {
  203. //_assetsAudioPlayer.forward(Duration(seconds: 10));
  204. assetsAudioPlayer.next(
  205. keepLoopMode:
  206. true /*keepLoopMode: false*/);
  207. },
  208. onPrevious: () {
  209. assetsAudioPlayer.previous(
  210. /*keepLoopMode: false*/);
  211. },
  212. );
  213. });
  214. },
  215. ),
  216. ),
  217. ],
  218. );
  219. })),
  220. panel: Container(
  221. decoration: BoxDecoration(
  222. color: Color(0xff002e5b).withOpacity(0.6),
  223. ),
  224. child: SingleChildScrollView(
  225. child: Column(
  226. mainAxisAlignment: MainAxisAlignment.center,
  227. crossAxisAlignment: CrossAxisAlignment.center,
  228. children: [
  229. assetsAudioPlayer.builderCurrent(
  230. builder: (context, playing) {
  231. if (playing == null) {
  232. return SizedBox();
  233. }
  234. final myAudio =
  235. find(audios, playing.audio.assetAudioPath);
  236. return Padding(
  237. padding: const EdgeInsets.only(
  238. top: 80, left: 8.0, right: 8.0, bottom: 90),
  239. child: Column(
  240. children: <Widget>[
  241. assetsAudioPlayer.builderRealtimePlayingInfos(
  242. builder: (context, infos) {
  243. if (infos == null) {
  244. return SizedBox();
  245. }
  246. return Column(
  247. children: [
  248. FlatButton(
  249. child: Icon(
  250. Icons.expand_more,
  251. size: 30,
  252. ),
  253. onPressed: () {
  254. panelController.close();
  255. },
  256. ),
  257. SizedBox(
  258. height: 5.0,
  259. ),
  260. Text(
  261. myAudio.metas.title,
  262. style: Theme.of(context)
  263. .textTheme
  264. .bodyText1,
  265. ),
  266. SizedBox(
  267. height: 10.0,
  268. ),
  269. Container(
  270. decoration: BoxDecoration(
  271. borderRadius:
  272. BorderRadius.circular(10),
  273. border: Border.all(
  274. color: Colors.white60)),
  275. child: ClipRRect(
  276. borderRadius:
  277. BorderRadius.circular(10.0),
  278. child: Image.network(
  279. myAudio.metas.image.path,
  280. height: 250,
  281. fit: BoxFit.fill,
  282. ),
  283. ),
  284. ),
  285. SizedBox(
  286. height: 10.0,
  287. ),
  288. PositionSeekWidget(
  289. currentPosition: infos.currentPosition,
  290. duration: infos.duration,
  291. seekTo: (to) {
  292. assetsAudioPlayer.seek(to);
  293. },
  294. ),
  295. ],
  296. );
  297. }),
  298. assetsAudioPlayer.builderLoopMode(
  299. builder: (context, loopMode) {
  300. return PlayerBuilder.isPlaying(
  301. player: assetsAudioPlayer,
  302. builder: (context, isPlaying) {
  303. return PlayingControls(
  304. loopMode: loopMode,
  305. isPlaying: isPlaying,
  306. isPlaylist: true,
  307. onStop: () {
  308. assetsAudioPlayer.stop();
  309. panelController.hide();
  310. },
  311. toggleLoop: () {
  312. assetsAudioPlayer.toggleLoop();
  313. },
  314. onPlay: () {
  315. assetsAudioPlayer.playOrPause();
  316. },
  317. onNext: () {
  318. //_assetsAudioPlayer.forward(Duration(seconds: 10));
  319. assetsAudioPlayer.next(
  320. keepLoopMode:
  321. true /*keepLoopMode: false*/);
  322. },
  323. onPrevious: () {
  324. assetsAudioPlayer.previous(
  325. /*keepLoopMode: false*/);
  326. },
  327. );
  328. });
  329. },
  330. ),
  331. /*
  332. PlayerBuilder.volume(
  333. player: assetsAudioPlayer,
  334. builder: (context, volume) {
  335. return VolumeSelector(
  336. volume: volume,
  337. onChange: (v) {
  338. assetsAudioPlayer.setVolume(v);
  339. },
  340. );
  341. }),
  342. */
  343. ],
  344. ),
  345. );
  346. }),
  347. ],
  348. ),
  349. ),
  350. ),
  351. ),
  352. ],
  353. ),
  354. ),
  355. ),
  356. );
  357. }
  358. }