my_timezone 0.0.3
my_timezone: ^0.0.3 copied to clipboard
A flutter plugin for getting the local timezone of the device on Android, ios, macos.
my_timezone is a Flutter plugin that returns the local timezone and available timezones on Android, iOS, macOS, and web.
Features #
- Get the local timezone from the native layer.
- Get the list of available timezones.
- Works across Android, iOS, macOS, and web.
Installation #
Add the following to your pubspec.yaml:
my_timezone: ^0.0.1+4
Then run:
flutter pub get
Basic usage #
import 'package:my_timezone/my_timezone.dart';
final String localTimezone = await MyTimezone.getLocalTimezone();
final List<String> availableTimezones =
await MyTimezone.getAvailableTimezones();
Example in a widget #
class _MyAppState extends State<MyApp> {
String? _timezone;
@override
void initState() {
super.initState();
_loadTimezone();
}
Future<void> _loadTimezone() async {
final timezone = await MyTimezone.getLocalTimezone();
if (!mounted) return;
setState(() => _timezone = timezone);
}
}
Contribution #
If you have any suggestions or find any issues, feel free to open an issue or submit a pull request on GitHub.