flutter_system_ringtones_advanced 2.0.2 copy "flutter_system_ringtones_advanced: ^2.0.2" to clipboard
flutter_system_ringtones_advanced: ^2.0.2 copied to clipboard

PlatformAndroid

Retrieve system ringtones, alarms, and notification sounds on Android using native APIs.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show PlatformException;
import 'package:flutter_system_ringtones_advanced/flutter_system_ringtones_advanced.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<Ringtone> ringtones = [];
  String? errorMessage;

  @override
  void initState() {
    super.initState();
    getRingtones();
  }

  Future<void> getRingtones() async {
    try {
      final temp = await FlutterSystemRingtones.getRingtoneSounds();
      if (!mounted) return;
      setState(() {
        ringtones = temp;
        errorMessage = null;
      });
    } on PlatformException catch (e) {
      if (!mounted) return;
      setState(() {
        errorMessage = e.message;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            if (!FlutterSystemRingtones.isSupported)
              const Padding(
                padding: EdgeInsets.all(16),
                child: Text(
                  'System ringtone listing is only supported on Android. '
                  'On iOS this example shows an empty list.',
                ),
              ),
            if (errorMessage != null)
              Padding(
                padding: const EdgeInsets.all(16),
                child: Text(
                  errorMessage!,
                  style: TextStyle(color: Theme.of(context).colorScheme.error),
                ),
              ),
            Expanded(
              child: ListView.builder(
                itemCount: ringtones.length,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(
                    title: Text(ringtones[index].title),
                    subtitle: Text(ringtones[index].uri),
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
160
points
134
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Retrieve system ringtones, alarms, and notification sounds on Android using native APIs.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

equatable, flutter, plugin_platform_interface

More

Packages that depend on flutter_system_ringtones_advanced

Packages that implement flutter_system_ringtones_advanced