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

A Flutter plugin to check the system time format (12h/24h) and get platform version.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:rigid_datetime/rigid_datetime.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool is24Hour = false;
  DateTime currentTime = DateTime.now();

  @override
  void initState() {
    super.initState();
    loadTimeFormat();

    Timer.periodic(const Duration(seconds: 1), (timer) {
      setState(() {
        currentTime = DateTime.now();
      });
    });
  }

  Future<void> loadTimeFormat() async {
    final value = await RigidDatetime().getTimeFormat();

    setState(() {
      is24Hour = value;
    });
  }

  @override
  Widget build(BuildContext context) {
    final date = DateFormat('dd MMM yyyy').format(currentTime);

    final time = is24Hour
        ? DateFormat('HH:mm').format(currentTime)
        : DateFormat('hh:mm a').format(currentTime);

    return Scaffold(
      appBar: AppBar(
        title: const Text('Rigid Datetime Example'),
      ),
      body: ColoredBox(
        color: Colors.deepPurple,
        child: Row(
          children: [
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(
                    "Date : $date",
                    style: const TextStyle(fontSize: 22,color: Colors.white),
                  ),
                  const SizedBox(height: 16),
                  Text(
                    "Time : $time",
                    style: const TextStyle(fontSize: 22,color: Colors.white),
                  ),
                  const SizedBox(height: 16),
                  Text(
                    "System Time Format : ${is24Hour ? "24 Hour Format" : "12 Hour Format"}",
                    style: const TextStyle(
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                        color: Colors.white
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
150
points
75
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to check the system time format (12h/24h) and get platform version.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter, intl, plugin_platform_interface

More

Packages that depend on rigid_datetime

Packages that implement rigid_datetime