123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- import 'package:flutter/material.dart';
- import 'package:double_back_to_close/double_back_to_close.dart';
- import 'package:convex_bottom_bar/convex_bottom_bar.dart';
- import 'package:sliding_up_panel/sliding_up_panel.dart';
- import 'package:assets_audio_player/assets_audio_player.dart';
- import 'package:empty/components/background.dart';
- import 'package:empty/components/playing_control.dart';
- import 'package:empty/components/position_seek_widget.dart';
- import 'package:empty/screens/home_screen.dart';
- import 'package:empty/screens/body_screen.dart';
- import 'package:empty/screens/mind_screen.dart';
- import 'package:empty/constants.dart';
- class MainScreen extends StatefulWidget {
- @override
- _MainScreenState createState() => _MainScreenState();
- }
- class _MainScreenState extends State<MainScreen> {
- TabController _tabController;
- int _selectedPage = 1;
- final double _initFabHeight = 120.0;
- double _fabHeight;
- double _panelHeightOpen;
- double _panelHeightClosed = 95.0;
- bool _panelState = false;
- Audio find(List<Audio> source, String fromPath) {
- return source.firstWhere((element) => element.path == fromPath);
- }
- Widget _pageOptions(int index) {
- switch (index) {
- case 0:
- return BodyScreen();
- break;
- case 1:
- return HomeScreen();
- break;
- case 2:
- return MindScreen();
- break;
- }
- }
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- /*
- subscriptions.add(assetsAudioPlayer.playlistAudioFinished.listen((data) {
- // print("playlistAudioFinished : $data");
- panelController.hide();
- }));
- subscriptions.add(assetsAudioPlayer.audioSessionId.listen((sessionId) {
- print("audioSessionId : $sessionId");
- }));
- subscriptions.add(assetsAudioPlayer.current.listen((data) {
- print("current : $data");
- }));
- subscriptions.add(assetsAudioPlayer.onReadyToPlay.listen((audio) {
- print("onReadyToPlay : $audio");
- }));
- subscriptions.add(assetsAudioPlayer.isBuffering.listen((isBuffering) {
- print("isBuffering : $isBuffering");
- }));
- subscriptions.add(assetsAudioPlayer.playerState.listen((playerState) {
- print("playerState : $playerState");
- }));
- subscriptions.add(assetsAudioPlayer.isPlaying.listen((isplaying) {
- print("isplaying : $isplaying");
- }));
- */
- subscriptions
- .add(AssetsAudioPlayer.addNotificationOpenAction((notification) {
- return false;
- }));
- _fabHeight = _initFabHeight;
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- assetsAudioPlayer.dispose();
- }
- @override
- Widget build(BuildContext context) {
- _panelHeightOpen = MediaQuery.of(context).size.height * .90;
- return DoubleBack(
- message: "'뒤로' 버튼을 한번더 누르시면 종료됩니다.",
- child: Background(
- image: Container(
- height: double.infinity,
- width: double.infinity,
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage('assets/images/background_body.png'),
- fit: BoxFit.cover)),
- ),
- child: Scaffold(
- backgroundColor: Colors.transparent,
- // extendBodyBehindAppBar: true,
- appBar: AppBar(
- title: Text('EMPTY'),
- centerTitle: true,
- backgroundColor: Color.fromRGBO(0, 41, 91, 0.5),
- elevation: 0.0,
- leading: IconButton(
- icon: Icon(Icons.help_outline),
- onPressed: () {
- assetsAudioPlayer.stop();
- panelController.hide();
- Navigator.pushNamed(context, '/guide');
- },
- ),
- actions: [
- IconButton(
- icon: Icon(Icons.menu),
- onPressed: () {
- Navigator.pushNamed(context, '/config');
- }),
- ],
- ),
- bottomNavigationBar: ConvexAppBar(
- controller: _tabController,
- height: 60,
- curveSize: 100,
- activeColor: Colors.blue[200],
- // style: TabStyle.fixedCircle,
- items: [
- TabItem(icon: Icons.accessibility, title: 'BODY'),
- TabItem(icon: Icons.home, title: 'HOME'),
- TabItem(icon: Icons.favorite, title: 'MIND'),
- ],
- initialActiveIndex: _selectedPage,
- onTap: (int i) {
- setState(() {
- _selectedPage = i;
- });
- },
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- colors: [Color(0xff0b3762), Color(0xff002e5b)]),
- ),
- body: Stack(
- alignment: Alignment.topCenter,
- children: [
- SlidingUpPanel(
- maxHeight: _panelHeightOpen,
- minHeight: _panelHeightClosed,
- backdropEnabled: true,
- parallaxEnabled: true,
- color: Colors.transparent,
- controller: panelController,
- body: _pageOptions(_selectedPage),
- collapsed: Container(
- padding: EdgeInsets.only(top: 0),
- decoration: BoxDecoration(
- color: Colors.black.withOpacity(0.9),
- ),
- child: assetsAudioPlayer.builderCurrent(
- builder: (context, playing) {
- if (playing == null) {
- return SizedBox();
- }
- return Row(
- mainAxisSize: MainAxisSize.max,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- Expanded(
- child: assetsAudioPlayer
- .builderRealtimePlayingInfos(
- builder: (context, infos) {
- if (infos == null) {
- return SizedBox();
- }
- return PositionSeekWidget(
- currentPosition: infos.currentPosition,
- duration: infos.duration,
- seekTo: (to) {
- assetsAudioPlayer.seek(to);
- },
- );
- }),
- ),
- Container(
- child: assetsAudioPlayer.builderLoopMode(
- builder: (context, loopMode) {
- return PlayerBuilder.isPlaying(
- player: assetsAudioPlayer,
- builder: (context, isPlaying) {
- return PlayingControls(
- loopMode: loopMode,
- isPlaying: isPlaying,
- isPlaylist: true,
- onStop: () {
- assetsAudioPlayer.stop();
- panelController.hide();
- },
- toggleLoop: () {
- assetsAudioPlayer.toggleLoop();
- },
- onPlay: () {
- assetsAudioPlayer.playOrPause();
- },
- onNext: () {
- //_assetsAudioPlayer.forward(Duration(seconds: 10));
- assetsAudioPlayer.next(
- keepLoopMode:
- true /*keepLoopMode: false*/);
- },
- onPrevious: () {
- assetsAudioPlayer.previous(
- /*keepLoopMode: false*/);
- },
- );
- });
- },
- ),
- ),
- ],
- );
- })),
- panel: Container(
- decoration: BoxDecoration(
- color: Color(0xff002e5b).withOpacity(0.6),
- ),
- child: SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- assetsAudioPlayer.builderCurrent(
- builder: (context, playing) {
- if (playing == null) {
- return SizedBox();
- }
- final myAudio =
- find(audios, playing.audio.assetAudioPath);
- return Padding(
- padding: const EdgeInsets.only(
- top: 80, left: 8.0, right: 8.0, bottom: 90),
- child: Column(
- children: <Widget>[
- assetsAudioPlayer.builderRealtimePlayingInfos(
- builder: (context, infos) {
- if (infos == null) {
- return SizedBox();
- }
- return Column(
- children: [
- FlatButton(
- child: Icon(
- Icons.expand_more,
- size: 30,
- ),
- onPressed: () {
- panelController.close();
- },
- ),
- SizedBox(
- height: 5.0,
- ),
- Text(
- myAudio.metas.title,
- style: Theme.of(context)
- .textTheme
- .bodyText1,
- ),
- SizedBox(
- height: 10.0,
- ),
- Container(
- decoration: BoxDecoration(
- borderRadius:
- BorderRadius.circular(10),
- border: Border.all(
- color: Colors.white60)),
- child: ClipRRect(
- borderRadius:
- BorderRadius.circular(10.0),
- child: Image.network(
- myAudio.metas.image.path,
- height: 250,
- fit: BoxFit.fill,
- ),
- ),
- ),
- SizedBox(
- height: 10.0,
- ),
- PositionSeekWidget(
- currentPosition: infos.currentPosition,
- duration: infos.duration,
- seekTo: (to) {
- assetsAudioPlayer.seek(to);
- },
- ),
- ],
- );
- }),
- assetsAudioPlayer.builderLoopMode(
- builder: (context, loopMode) {
- return PlayerBuilder.isPlaying(
- player: assetsAudioPlayer,
- builder: (context, isPlaying) {
- return PlayingControls(
- loopMode: loopMode,
- isPlaying: isPlaying,
- isPlaylist: true,
- onStop: () {
- assetsAudioPlayer.stop();
- panelController.hide();
- },
- toggleLoop: () {
- assetsAudioPlayer.toggleLoop();
- },
- onPlay: () {
- assetsAudioPlayer.playOrPause();
- },
- onNext: () {
- //_assetsAudioPlayer.forward(Duration(seconds: 10));
- assetsAudioPlayer.next(
- keepLoopMode:
- true /*keepLoopMode: false*/);
- },
- onPrevious: () {
- assetsAudioPlayer.previous(
- /*keepLoopMode: false*/);
- },
- );
- });
- },
- ),
- /*
- PlayerBuilder.volume(
- player: assetsAudioPlayer,
- builder: (context, volume) {
- return VolumeSelector(
- volume: volume,
- onChange: (v) {
- assetsAudioPlayer.setVolume(v);
- },
- );
- }),
- */
- ],
- ),
- );
- }),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|