get_time_ago 0.0.5 copy "get_time_ago: ^0.0.5" to clipboard
get_time_ago: ^0.0.5 copied to clipboard

outdated

A new Flutter package for getting time formats in secons, minutes, hours, days and date.

example/main.dart

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

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var _dateTime = DateTime.now();
  var _timestamp = '2020-09-10 05:21:37.712498';

  Future<void> _selectDate() async {
    DateTime pickedDate = await showDatePicker(
        context: context,
        initialDate: DateTime.now(),
        firstDate: DateTime(1900),
        lastDate: DateTime.now());
    if (pickedDate != null) {
      setState(() {
        _dateTime = pickedDate;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("GetTimeAgo Example"),
      ),
      body: Container(
        padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
        child: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              FlatButton.icon(
                onPressed: _selectDate,
                label: Text("Select DateTime"),
                color: Theme.of(context).accentColor,
                textColor: Colors.white,
                icon: Icon(Icons.calendar_today),
              ),
              SizedBox(height: 20.0),
              Text(
                "Converting DateTime to TimeAgo",
                style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 10.0),
              Text(_dateTime.toString()),
              Text(
                TimeAgo.getTimeAgo(_dateTime),
                style: TextStyle(
                    color: Theme.of(context).accentColor,
                    fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 20.0),
              Text(
                "Converting String to TimeAgo",
                style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 10.0),
              Text(_timestamp),
              Text(
                TimeAgo.getTimeAgo(DateTime.parse(_timestamp)),
                style: TextStyle(
                    color: Theme.of(context).accentColor,
                    fontWeight: FontWeight.bold),
              )
            ],
          ),
        ),
      ),
    );
  }
}
132
likes
0
pub points
96%
popularity

Publisher

verified publishernixrajput.com

A new Flutter package for getting time formats in secons, minutes, hours, days and date.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, intl

More

Packages that depend on get_time_ago