How to play sound on button press

Add audioplayers as a dependency and your audio file to pubspec.yaml file like this: dependencies: audioplayers: ^1.0.1 flutter: assets: – assets/audio/my_audio.mp3 Full code (Null-safe): class _HomePageState extends State<HomePage> { @override Widget build(BuildContext context) { return Scaffold( body: ElevatedButton( onPressed: () => AudioPlayer().play(AssetSource(‘audio/my_audio.mp3’)); child: Text(‘Play’), ), ); } }

How to validate email in a TextFormField

You can use regex for this Form and TextFormField like so Form( autovalidateMode: AutovalidateMode.always, child: TextFormField( validator: validateEmail, ), ) then the validation function String? validateEmail(String? value) { const pattern = r”(?:[a-z0-9!#$%&’*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'” r’*+/=?^_`{|}~-]+)*|”(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-‘ r’\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*”)@(?:(?:[a-z0-9](?:[a-z0-9-]*’ r'[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4]’ r'[0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9]’ r'[0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\’ r’x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])’; final regex = RegExp(pattern); return value!.isNotEmpty && !regex.hasMatch(value) ? ‘Enter a valid email address’ : null; } … Read more

Scroll through Flutter Bottom Sheet

I’ve found a solution implementing the code below void _showBottomSheet(BuildContext context) { showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) { return GestureDetector( onTap: () => Navigator.of(context).pop(), child: Container( color: Color.fromRGBO(0, 0, 0, 0.001), child: GestureDetector( onTap: () {}, child: DraggableScrollableSheet( initialChildSize: 0.4, minChildSize: 0.2, maxChildSize: 0.75, builder: (_, controller) { return Container( decoration: … Read more

Flutter Web: Cannot scroll with mouse down (drag) (Flutter 2.5+)

My final solution was a combination of the suggestions, wanting drag scrolling everywhere, so used this: class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( scrollBehavior: MaterialScrollBehavior().copyWith( dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind.unknown}, ), … Simple enough…

How to find memory leaks in Flutter?

I am implemented Memory leak testing in android studio ide. Step – 1 : Connect your device with android studio and run your application on your device. Step – 2 : Go to View -> Tool Windows -> Flutter Performance Step – 3 : Bottom of the window Open Dev Tools option will be there, … Read more

Fastlane : [altool] Error: Unable to upload archive. Failed to get authorization for username and password

Hello I was struggling with this issue for many days. Solution Step 1 Go to https://appleid.apple.com/account/manage login in and go to App-Specific Passwords, after generate a new App Specific Password copy it. Step2 Inside fastlane folder create a new file .env.default and add the two properties . FASTLANE_USER=<Apple USER ID> FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=<App-Specific Password> Use an app-specific … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)