| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- import 'dart:async';
- import 'dart:convert';
- import 'package:assets_audio_player/assets_audio_player.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:trackoffical_app/generated/assets.dart';
- import 'package:trackoffical_app/logger.dart';
- import 'package:trackoffical_app/service/app.dart';
- import 'package:trackoffical_app/view/ingame/dialog/dialog_base.dart';
- import 'package:trackoffical_app/view/ingame/dialog/dialog_check_text.dart';
- import 'package:trackoffical_app/widget/app_net_image.dart';
- import '../../../model/cp_extra_info_choice_question.dart';
- import '../../../model/m_control_point.dart';
- import '../../../screen.dart';
- import '../../../styles/theme.dart';
- Future<void> showDialogCheckRich(
- MControlPoint point,
- Duration? offAfter,
- ) async {
- while(Get.isOverlaysOpen){
- Get.back();
- }
- Get.dialog(DialogCheckRichSeq(
- point,
- offAfter,
- ));
- }
- class DialogCheckRichSeq extends StatefulWidget{
- const DialogCheckRichSeq(
- this.point, this.offAfter, {super.key}
- );
- final MControlPoint point;
- final Duration? offAfter;
- @override
- State<StatefulWidget> createState() {
- return DialogCheckRichSeqState();
- }
- }
- class DialogCheckRichSeqState extends State<DialogCheckRichSeq>{
- var seq = 0;
- var beanCount=0;
- @override
- void initState() {
- super.initState();
- }
- @override
- void dispose() {
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final isShowOriginality = App.to.userProfile.gameSettingsShowOriginality.value;
- if(seq==0){
- return DialogCheckText(
- text: '打点成功',
- color: const Color(0xffff870d),
- beanCount: 1,
- autoPlayAfter: 1.seconds,
- closeAfterPlay: !isShowOriginality,
- onStop: (){
- if(mounted){
- if (widget.point.extraInfo != null && isShowOriginality) {
- setState(() {
- seq = 1;
- });
- }
- }
- },
- );
- }
- if(seq==1){
- return DialogCheckRich(
- point: widget.point,
- offAfter: widget.offAfter,
- onBeanCount: (c) {
- beanCount = c;
- },
- onStop: (){
- if(mounted){
- setState(() {
- seq = 2;
- });
- }
- },
- );
- }
- if(seq==2){
- return DialogCheckText(
- text: '',
- color: const Color(0xffff870d),
- beanCount: beanCount,
- autoPlayAfter: 1.seconds,
- );
- }
- throw UnimplementedError();
- }
- }
- class DialogCheckRich extends DialogBaseOffCount {
- const DialogCheckRich({
- super.key,
- required this.point,
- required super.offAfter,
- required this.onBeanCount,
- required this.onStop
- }) : super(child: const SizedBox());
- final Function(int c) onBeanCount;
- final MControlPoint point;
- final VoidCallback onStop;
- @override
- State<StatefulWidget> createState() {
- return DialogCheckRichState();
- }
- }
- class DialogCheckRichState extends DialogBaseOffCountState<DialogCheckRich> {
- int? selectedIndex;
- var isFinish = false;
- final _audioPlayer = AssetsAudioPlayer.newPlayer();
- var isAnswerOk = false;
- @override
- void onStop() {
- widget.onStop();
- }
- void _setFinish() {
- setState(() {
- isFinish = true;
- });
- final src = isAnswerOk ? Assets.soundAnswerOk : Assets.soundAnswerFail;
- _audioPlayer.open(
- Audio(src),
- autoStart: true,
- showNotification: false,
- );
- 1.seconds.delay().then((value) {
- if (isActive && Get.isOverlaysOpen) {
- // Get.back();
- widget.onStop();
- }
- });
- }
- @override
- void dispose() {
- _audioPlayer.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final style = (context.textTheme.titleLarge ?? const TextStyle())
- .copyWith(color: const Color(0xff333333), fontSize: 41.98.rpx);
- return DefaultTextStyle(
- style: style,
- child: Container(
- width: context.width,
- height: context.height,
- color: const Color(0xB8000000),
- alignment: Alignment.center,
- child: Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- decoration: BoxDecoration(
- color: const Color(0xE6FFFCF4),
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(2.25.wp),
- bottomRight: Radius.circular(2.25.wp))),
- padding: EdgeInsets.fromLTRB(
- 4.5.wp,
- MediaQuery.of(context).padding.top + 4.5.wp,
- 4.5.wp,
- 11.4.wp),
- child: _wRich(),
- ),
- Obx(() => offCount(secondCount.value)),
- const Spacer()
- ],
- ),
- ),
- ));
- }
- Widget _wTitle(CPExtraInfoChoiceQuestion extraInfo) {
- const color = Color(0x80000000);
- return Row(
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Image.asset(Assets.imagesWarnFastThinker, width: 9.67.wp, color: color),
- Text(
- '快速思考',
- style: TextStyle(color: color, fontSize: 4.58.wp),
- ),
- Text(
- ' Think Fast',
- style: TextStyle(color: const Color(0x33333333), fontSize: 3.56.wp),
- ),
- const Spacer(),
- bean(extraInfo.beanCount, 3.31.wp)
- ],
- );
- }
- Widget _wRich() {
- final extraInfo = widget.point.extraInfo!;
- if (extraInfo is CPExtraInfoChoiceQuestion) {
- return wExtraInfoChoiceQuestion(extraInfo);
- } else {
- throw UnimplementedError('wExtraInfo: $extraInfo 未实现');
- }
- }
- Widget wExtraInfoChoiceQuestion(CPExtraInfoChoiceQuestion extraInfo) {
- final children = <Widget>[];
- var hasImage = false;
- if (extraInfo.image != null) {
- if (extraInfo.image!.md5.isNotEmpty) {
- hasImage = true;
- children.add(Container(
- decoration: BoxDecoration(
- border: Border.all(color: Colors.white, width: 0.78.wp),
- borderRadius: BorderRadius.circular(1.78.wp)),
- clipBehavior: Clip.hardEdge,
- height: 40.97.wp,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(1.78.wp),
- child: AppNetImage(
- netImage: extraInfo.image!,
- fit: BoxFit.fitHeight,
- ))));
- }
- }
- children.addAll([
- SizedBox(height: 2.29.wp),
- ConstrainedBox(
- constraints: hasImage
- ? const BoxConstraints()
- : BoxConstraints(minHeight: 26.0.wp),
- child: Container(
- width: double.infinity,
- alignment: Alignment.centerLeft,
- child: Text(extraInfo.question, style: TextStyle(fontSize: 4.58.wp)),
- ),
- ),
- SizedBox(height: 2.29.wp),
- ]);
- var ascii = 65;
- for (var i = 0; i < extraInfo.answers.length; i++) {
- final one = extraInfo.answers[i];
- final sn = const Utf8Codec().decode([ascii]);
- final selected = i == selectedIndex;
- children.add(GestureDetector(
- onTap: () async {
- if (selectedIndex == null) {
- setState(() {
- selectedIndex = i;
- });
- if (i == extraInfo.rightIndex) {
- widget.onBeanCount(extraInfo.beanCount);
- }
- widget.point.userAnswerIndex = selectedIndex;
- widget.point.isAnswerCorrect =
- selectedIndex == extraInfo.rightIndex;
- isAnswerOk = widget.point.isAnswerCorrect;
- _setFinish();
- }
- },
- child: Container(
- margin: EdgeInsets.only(top: 2.8.wp, bottom: 2.8.wp),
- padding: EdgeInsets.only(left: 4.8.wp),
- alignment: Alignment.centerLeft,
- decoration: BoxDecoration(
- color: Color(selected ? 0xff00a0ff : 0xff017dc7),
- borderRadius: BorderRadius.circular(1.78.wp)),
- height: 13.49.wp,
- width: double.infinity,
- child: Text('$sn. $one',
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(color: Colors.white)))));
- ascii++;
- }
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- _wTitle(extraInfo),
- const Divider(),
- Padding(
- padding: EdgeInsets.only(left: 8.52.wp, right: 8.52.wp, top: 7.26),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: children,
- ))
- ],
- );
- }
- }
- class _Empty extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- SizeFit.screenInit(context);
- final info = CPExtraInfoChoiceQuestion()
- ..question = '计算题 23 + 8 - 6 = ?'
- ..answers = ['22', '2312312312311', '242323', '21231231211111231235']
- ..rightIndex = 3;
- return Scaffold(
- floatingActionButton: FloatingActionButton(
- onPressed: () => showDialogCheckRich(
- MControlPoint()
- ..sn = '3'
- ..areaId = 'A55'
- ..checkAfterPrev = 2.1.minutes
- ..extraInfo = info,
- 3.seconds,
- )),
- );
- }
- }
- void main() async {
- runApp(GetMaterialApp(theme: appThemeData(), home: _Empty()));
- }
|