import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() {
runApp(const XylophoneApp());
}
class XylophoneApp extends StatelessWidget {
const XylophoneApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: TextButton(onPressed: () {
final player = Audiocache();
player.play('note1.wav');
},
child: Text('Click Me'),
),
),
),
),
);
}
}
when i click on run button it says "Error: Not a constant expression." and when i write a new onPressed on an another project its still the same error.
Remove const
modifier on MaterialApp
will do the fix.
const MaterialApp
-> MaterialApp
.