device_time_format 0.0.1 copy "device_time_format: ^0.0.1" to clipboard
device_time_format: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin to get the device's current time and detect whether the system uses 12-hour or 24-hour format.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:device_time_format/device_time_format.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _deviceTimeFormatPlugin = DeviceTimeFormat();

  String _deviceTime = 'Unknown';
  bool _is24Hour = false;

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

  Future<void> fetchTimeInfo() async {
    String? time;
    bool? is24Hour;

    try {
      time = await _deviceTimeFormatPlugin.getDeviceTime();
      is24Hour = await _deviceTimeFormatPlugin.is24HourFormat();
    } catch (e) {
      time = 'Error: $e';
    }

    if (!mounted) return;

    setState(() {
      _deviceTime = time ?? 'Unknown';
      _is24Hour = is24Hour ?? false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Device Time Format Plugin')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Current Device Time:',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              const SizedBox(height: 10),
              Text(
                _deviceTime,
                style: const TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 20),
              Text(
                _is24Hour ? 'Format: 24-hour' : 'Format: 12-hour (AM/PM)',
                style: Theme.of(context).textTheme.titleMedium,
              ),
              const SizedBox(height: 30),
              ElevatedButton(
                onPressed: fetchTimeInfo,
                child: const Text('Refresh Time'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
4
likes
150
points
66
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to get the device's current time and detect whether the system uses 12-hour or 24-hour format.

Homepage

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on device_time_format

Packages that implement device_time_format