У меня есть простое приложение трепетания, которое воспроизводит шум коры при нажатии на аватар Круга собаки. Если я храню свои аудиофайлы в файле pubspe c .yaml следующим образом, то он работает
flutter:
uses-material-design: true
assets:
- assets/
- images/
Аватар оборачивается виджетом FlatButton, а метод onPressed выглядит следующим образом:
onPressed: (){
audioCache.play('bark.mp3');
},
НО, то же самое не происходит, когда я сохраняю аудиофайл в каталоге «audio», например:
flutter:
uses-material-design: true
assets:
- audios/
- images/
И метод onPressed:
onPressed: (){
audioCache.play('audios/bark.mp3');
},
Когда я сохраняю аудиофайл, используя второй метод, он выдает следующую ошибку:
Cannot find asset: "assets/audios/bark.mp3"
В чем может быть проблема?
Вот следующий код в main.dart
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
// The main function is the starting point.
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
AudioCache audioCache;
@override
void initState() {
// TODO: implement initState
super.initState();
audioCache = AudioCache();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.indigo[300],
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: (){
audioCache.play('bark.mp3');
},
child: CircleAvatar(
radius: 50,
backgroundImage: AssetImage("images/doggo.jpg"),
),
),
Text(
"Roger Pupperino",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Pacifico',
),
),
Text(
"Goodest Boi Ever".toUpperCase(),
style: TextStyle(
fontFamily: 'SourceSansPro',
color: Colors.indigo,
letterSpacing: 2.5,
),
),
SizedBox(
height: 20,
width: 200,
child: Divider(
color: Colors.indigo[300],
),
),
Card(
margin: EdgeInsets.symmetric(vertical: 10,horizontal: 25),
color: Colors.white,
child: ListTile(
leading: Icon(Icons.phone, color: Colors.indigo),
title: Text(
"+880 13033 84426",
style: TextStyle(
color: Colors.indigo,
fontFamily: 'Source Sans Pro',
fontSize: 20,
),
),
),
),
Card(
margin: EdgeInsets.symmetric(vertical: 10,horizontal: 25),
color: Colors.white,
child: ListTile(
leading: Icon(Icons.mail, color: Colors.indigo),
title: Text(
"roger.goodboi@pup.com",
style: TextStyle(
color: Colors.indigo,
fontFamily: 'Source Sans Pro',
fontSize: 20,
),
),
),
),
],
),
),
),
);
}
}
Ниже у меня есть изображение дерева каталогов. Обратите внимание, что папка aud ios и images находятся в каталоге root. Изображения работают нормально, но Aud ios не работает.
