断言失败:第 464 行 pos 12:“needsCompositing”:不正确。如何解决这个问题?

问题描述 投票:0回答:1

我开始颤抖。我想在应用程序中插入音频播放,但它不起作用。我正在使用库 "assets_audio_player: ^3.1.1" 因为我的类是 'StatelessWidget'。我认为错误原因是 FlexibleSpaceBar 小部件,但我没有解决方案。当我运行此代码时,出现此错误:'断言失败:第 464 行 pos 12:'needsCompositing':不是 true。”

错误:

The following assertion was thrown during paint():
'package:flutter/src/material/flexible_space_bar.dart': Failed assertion: line 464 pos 12: 'needsCompositing': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was: 
  FlexibleSpaceBar FlexibleSpaceBar:file:///C:/Users/ruama.patricio/AndroidStudioProjects/shopping/lib/pages/course.page.dart:131:30
When the exception was thrown, this was the stack: 
#2      _RenderFlexibleSpaceHeaderOpacity.paint (package:flutter/src/material/flexible_space_bar.dart:464:12)
#3      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#4      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#5      RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2875:15)
#6      RenderStack.paintStack (package:flutter/src/rendering/stack.dart:639:5)
#7      PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:535:83)
#8      ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
#9      ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)

代码


import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:assets_audio_player/assets_audio_player.dart';

var url = 'https://www.kozco.com/tech/LRMonoPhase4.mp3';
final audioo = AssetsAudioPlayer();

playAudiofromAssets() {
  print("Played");
  audioo.open(
    Audio('assets/audios/ash.mp3'),
  );
  audioo.playOrPause();
}

playAudiofromInt() {
  print("p");
  audioo.open(Audio.network(url));
}

stopAudio() {
  audioo.pause();
}



class CheckboxProvider with ChangeNotifier {
  bool _isChecked = false;

  bool get isChecked => _isChecked;

  set isChecked(bool value) {
    _isChecked = value;
    notifyListeners();
  }
}
class CheckboxProviderAudio with ChangeNotifier {
  bool _isCheckedAudio = false;

  bool get isCheckedAudio => _isCheckedAudio;

  set isCheckedAudio(bool value) {
    _isCheckedAudio = value;
    notifyListeners();
  }
}




class CoursePage extends StatelessWidget {
  final String image;
  final String title;
  final String description;
  final String logo;
  final String details;
  final String company;


  CoursePage({
    required this. title,
    required this.description,
    required this.image,
    required this.logo,
    required this.details,
    required this.company,
  });

  @override
  Widget build(BuildContext context) {



    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled){
          return <Widget>[
            SliverAppBar(
              leadingWidth: 400,
              leading: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[

                  Flexible(

                    child: Padding(
                      padding: const EdgeInsets.only(right:4),
                      child:  InkWell(
                        onTap: () {
                          Navigator.pop(context);
                        },
                        child: Ink.image(
                          image: AssetImage("assets/item-voltar.png"),
                          width: 40,
                          height: 40,
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                  ),

                  Spacer(),


                 Flexible(
                    child: Padding(
                      padding: const EdgeInsets.only(right: 0),
                      child:  InkWell(
                        onTap: () {
                       //   Navigator.pop(context);
                        },
                        child: Ink.image(
                          image: AssetImage("assets/component.png"),
                          width: 80,
                          height: 40,
                          fit: BoxFit.fill,
                        ),
                      ),
                    ),
                  ),
                ],
              ),

              backgroundColor:  Colors.white.withOpacity(0),
              elevation: 0.0,
              expandedHeight: 500.0,
              floating: false,
              flexibleSpace: FlexibleSpaceBar(
                centerTitle: true,
                background: Hero(
                  tag: image,
                  child:  Image.asset(
                    image,
                    width: double.infinity,
                    fit: BoxFit.fitWidth,
                  ),
                ),
              ),
            ),
          ];

        },
        body:ListView(
          children: <Widget> [
          Row(
            children: [
              SizedBox(
                width: 10,
              ),
              Flexible(
                child: Padding(
                  padding: const EdgeInsets.only(right: 0),
                  child:  InkWell(
                    onTap: () {
                      //   Navigator.pop(context);
                    },
                    child: Ink.image(
                      image: AssetImage("assets/item-compartilhar.png"),
                      width: 40,
                      height: 40,
                      fit: BoxFit.fill,
                    ),
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.all(10),
                child: Text(description,
                   style: TextStyle(
                    fontSize: 20,
                  ),),
              ),
             Text("                             Por: "),
              Image.asset(logo, width: 50, height: 50,),

            ],

          ),
            Padding(
                padding: EdgeInsets.only(
                    top: 10,
                    left: 10,
                    right: 10
                ),
                child: Text(
                  title,
                  style: TextStyle(
                    fontSize: 26,
                    fontWeight: FontWeight.bold,
                  ),
                ),
            ),

            SizedBox(
              height: 10,
            ),
            Row(
              children: [
                SizedBox(width: 10),
                Icon(Icons.account_balance),
                Padding(
                  padding: EdgeInsets.all(10),
                  child: Text(
                    company,
                  ),
                ),

              ],
            ),


            SizedBox(
              height: 10,
            ),
            Padding(
              padding: EdgeInsets.all(10),
              child: Text(
                  "Sobre",
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.all(10),
              child: Text(
               details,
              ),
            ),


      Row(children: [
        Flexible(
              child: Column(
                  children: <Widget>[ description  == " Curso"
              ? Row(
                children: [
                  ChangeNotifierProvider(
                    create: (_) => CheckboxProvider(),
                    child: Consumer<CheckboxProvider>(
                      builder: (context, checkboxProvider, _) => Checkbox(
                        value: checkboxProvider.isChecked,
                        onChanged: (value) {
                          checkboxProvider.isChecked = value ?? true;
                        },
                      ),
                    ),
                  ),

                  Text(
                    "Fiz esse curso",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),



                ],

              )
                :Row(
                    children: [
                      ChangeNotifierProvider(
                        create: (_) => CheckboxProviderAudio(),
                        child: Consumer<CheckboxProviderAudio>(
                          builder: (context, checkboxProviderAudio, _) => Checkbox(
                            value: checkboxProviderAudio.isCheckedAudio,
                            onChanged: (value) {
                              checkboxProviderAudio.isCheckedAudio = value ?? true;
                            },
                          ),
                        ),
                      ),

                      Text(
                        "Já ouvi esse tutorial",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  )
                  ],
            )
                ),
         ],
      ),


         Padding(
             padding: EdgeInsets.all(10),
              child: Column(
                  children: <Widget>[ description  == " Curso"
                  ?
                Container(
                height: 200,
                width: 400,
               /* decoration: BoxDecoration(
                 color: Theme.of(context).primaryColor,
                  borderRadius: BorderRadius.all(
                    Radius.circular(50),
                  ),
                ),*/
                margin: EdgeInsets.only(right: 20),
                child: Column(
                  children: [


                    Flexible(child:  TextButton(
                    child: Row(

                      children: [
                        Icon(Icons.link, color: Colors.white,),
                        Text(
                          "Tenho Interesse",
                          textAlign: TextAlign.center,
                          style: Theme.of(context).textTheme.displayMedium,
                        ),
                      ],
                    ),
                    style:  const ButtonStyle(
                      backgroundColor: MaterialStatePropertyAll(Colors.cyan),

                    ),
                    onPressed: () => {},
                  ),

                  ),





                   Flexible(child:
                    TextButton(
                      child: Row(

                        children: [
                          Icon(Icons.calendar_month, color: Colors.white,),
                          Text(
                            "Adicionar ao calendário",
                            textAlign: TextAlign.center,
                            style: Theme.of(context).textTheme.displayMedium,
                          ),
                        ],
                      ),
                      style:  const ButtonStyle(
                        backgroundColor: MaterialStatePropertyAll(Colors.lightBlueAccent),

                      ),
                      onPressed: () => {},
                    ),
                    )

                   
                  ],
                ),

              )
                : Text("Áudio Player"),
            Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                                 Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                     mainAxisSize: MainAxisSize.min,
                                    children: <Widget>[
                                      Text(
                                        "PLAY AUDIO FROM ASSET",
                                        style: TextStyle(
                                            color: Colors.white,
                                            fontSize: 20,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        children: <Widget>[


                                          TextButton.icon(
                                            onPressed: playAudiofromAssets,
                                            style: TextButton.styleFrom(
                                              foregroundColor: Colors.grey[100],
                                            ),
                                            icon: Icon(Icons.play_arrow),
                                            label: Text(""),

                                          ),

                                          Spacer(),

                                          TextButton.icon(
                                            onPressed: stopAudio,
                                            style: TextButton.styleFrom(
                                              foregroundColor: Colors.grey[100],
                                            ),
                                            icon: Icon(Icons.pause),
                                            label: Text(""),

                                          ),

                                        ],
                                      ),
                                      Spacer(),
                                      Text(
                                        "PLAY AUDIO FROM INTERNET",
                                        style: TextStyle(
                                            color: Colors.white,
                                            fontSize: 20,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: <Widget>[
                                          TextButton.icon(
                                            //onPressed:(){},
                                           onPressed: () async {
                                              await audioo.open(Audio.network(url));
                                            },
                                            style: TextButton.styleFrom(
                                              foregroundColor: Colors.grey[100],
                                            ),
                                            icon: Icon(Icons.play_arrow),
                                            label: Text(""),
                                          ),

                                        Spacer(),
                                          TextButton.icon(
                                            onPressed:stopAudio,
                                            style: TextButton.styleFrom(
                                              foregroundColor: Colors.grey[100],
                                            ),
                                            icon: Icon(Icons.pause),
                                            label: Text(""),
                                          ),

                                        ],
                                      ),
                                    ],
                                  ),

                    ],

                    )

         ],
          ),
         ),
          ],

        ),
      ),
    );
  }
}


我想解决这个问题或遇到一个新的解决方案来在我的应用程序中插入音频播放器

flutter audio audio-player
1个回答
0
投票

我也遇到了同样的问题,我的解决方案是设置

backgroundColor: Colors.grey,

我调试了一下了解情况后,要求Gemini澄清,它回复:

  1. 确保正确设置不透明度:

FlexibleSpaceBar 依赖于合成图层来实现某些不透明效果。 确保FlexibleSpaceBar的opacity属性设置为0.0(完全透明)和1.0(完全不透明)之间的值。将其设置为 null 或忽略它可能会触发此错误。

所以请勿将背景设置为透明(或等效)

© www.soinside.com 2019 - 2024. All rights reserved.