292 lines
11 KiB
Dart
292 lines
11 KiB
Dart
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/dialog/dialog_base.dart';
|
|
import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_date_utils.dart';
|
|
import 'package:aslan/chatvibe_data/models/at_music_mode.dart';
|
|
import 'package:aslan/chatvibe_managers/audio_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/rtc_manager.dart';
|
|
|
|
import 'local/at_local_music_page.dart';
|
|
|
|
class ATRoomMusicPage extends StatefulWidget {
|
|
@override
|
|
_ATRoomMusicPageState createState() => _ATRoomMusicPageState();
|
|
}
|
|
|
|
class _ATRoomMusicPageState extends State<ATRoomMusicPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Provider.of<AudioManager>(context, listen: false).loadAtRoomMusics();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<AudioManager>(
|
|
builder: (context, ref, child) {
|
|
return SafeArea(
|
|
top: false,
|
|
child: ClipRect(
|
|
child: BackdropFilter(
|
|
filter: ui.ImageFilter.blur(sigmaX: 15, sigmaY: 15),
|
|
child: Container(
|
|
height: 480.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(12.w),
|
|
topRight: Radius.circular(12.w),
|
|
),
|
|
),
|
|
child: Stack(
|
|
alignment: AlignmentDirectional.topCenter,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 15.w),
|
|
Row(
|
|
children: [
|
|
Spacer(),
|
|
text(
|
|
ATAppLocalizations.of(context)!.myMusic,
|
|
fontSize: 14.sp,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
Spacer(),
|
|
],
|
|
),
|
|
SizedBox(height: 8.w),
|
|
Divider(
|
|
color: Colors.white24,
|
|
thickness: 3.w,
|
|
height: 28.w,
|
|
),
|
|
Expanded(
|
|
child:
|
|
ref.addedSongs.isNotEmpty
|
|
? ListView.separated(
|
|
itemBuilder:
|
|
(context, i) => _buildItem(
|
|
ref.addedSongs[i],
|
|
i,
|
|
ref,
|
|
),
|
|
itemCount: ref.addedSongs.length,
|
|
padding: EdgeInsets.zero,
|
|
separatorBuilder:
|
|
(context, i) => Container(height: 10.w),
|
|
)
|
|
: mainEmpty(
|
|
center: false,
|
|
textColor: Colors.black38,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 15.w),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 10.w),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Container(
|
|
color: Colors.transparent,
|
|
padding: EdgeInsets.all(3.w),
|
|
child: Icon(
|
|
Icons.arrow_back_ios,
|
|
size: 16.w,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
onTap: () {
|
|
SmartDialog.dismiss(tag: "showRoomMusic");
|
|
},
|
|
),
|
|
Spacer(),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Icon(
|
|
Icons.add,
|
|
size: 16.w,
|
|
color: Colors.black,
|
|
),
|
|
onTap: () {
|
|
SmartDialog.show(
|
|
tag: "showRoomLocalMusic",
|
|
alignment: Alignment.bottomCenter,
|
|
debounce: true,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return ATLocalMusicPage();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
GestureDetector(
|
|
child: Container(
|
|
color: Colors.transparent,
|
|
padding: EdgeInsets.all(3.w),
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.music,
|
|
fontSize: 11.sp,
|
|
textColor: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
onTap: () {
|
|
SmartDialog.dismiss(tag: "showRoomMusic");
|
|
SmartDialog.show(
|
|
tag: "showRoomLocalMusic",
|
|
debounce: true,
|
|
alignment: Alignment.bottomCenter,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return ATLocalMusicPage();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
SizedBox(width: 10.w),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildItem(ATMusicMode song, int i, AudioManager ref) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
bool isOnMai =
|
|
Provider.of<RtcProvider>(context, listen: false).isOnMai();
|
|
if (isOnMai) {
|
|
_play(i, song);
|
|
} else {
|
|
SmartDialog.show(
|
|
tag: "showConfirmDialog",
|
|
alignment: Alignment.center,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return MsgDialog(
|
|
msg: ATAppLocalizations.of(context)!.pleaseGetOnTheMicFirst,
|
|
onEnsure: () {
|
|
///上麦
|
|
num index =
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).findWheat();
|
|
if (index > -1) {
|
|
Provider.of<RtcProvider>(
|
|
context,
|
|
listen: false,
|
|
).shangMai(index);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
},
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
constraints: BoxConstraints(maxWidth: 260.w),
|
|
child: text(
|
|
song.title ?? "",
|
|
fontWeight: FontWeight.w600,
|
|
textColor:
|
|
ref.playingIndex == i
|
|
? ChatVibeTheme.primaryColor
|
|
: Colors.black,
|
|
fontSize: 14.sp,
|
|
),
|
|
),
|
|
SizedBox(width: 5.w),
|
|
ref.playingIndex == i
|
|
? Image.asset(
|
|
"atu_images/general/at_icon_online_user.gif",
|
|
width: 18.w,
|
|
)
|
|
: Container(),
|
|
],
|
|
),
|
|
SizedBox(height: 3.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.duration2(
|
|
ATMDateUtils.millisecondsToMinutesMethod(
|
|
song.duration ?? 0,
|
|
),
|
|
),
|
|
fontWeight: FontWeight.w600,
|
|
textColor: Colors.black38,
|
|
fontSize: 12.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
i == 0
|
|
? Container()
|
|
: GestureDetector(
|
|
child: Image.asset(
|
|
"atu_images/room/at_icon_music_to_up.png",
|
|
width: 18.w,
|
|
color: Colors.black,
|
|
),
|
|
onTap: () {
|
|
ref.toUp(song, i);
|
|
},
|
|
),
|
|
SizedBox(width: 10.w),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Image.asset(
|
|
"atu_images/room/at_icon_music_delete.png",
|
|
width: 18.w,
|
|
color: Colors.black,
|
|
),
|
|
onTap: () {
|
|
ref.addedSongs.removeAt(i);
|
|
ref.deleteRoomMusic(context, song);
|
|
setState(() {});
|
|
},
|
|
),
|
|
SizedBox(width: 10.w),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _play(int i, ATMusicMode song) {
|
|
Provider.of<AudioManager>(
|
|
context,
|
|
listen: false,
|
|
).playMusic(context, song, i);
|
|
}
|
|
}
|