days_ago 1.0.0 copy "days_ago: ^1.0.0" to clipboard
days_ago: ^1.0.0 copied to clipboard

outdated

Get time ago string, Just by passing Date and time.

example/lib/example.dart

import 'package:days_ago/days_ago.dart';
import 'package:flutter/material.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 List<DateTime> _listOfDate = List.generate(
      100,
      (index) => DateTime(
            DateTime.now().year,
            DateTime.now().month,
            DateTime.now().day - index,
            DateTime.now().hour,
            DateTime.now().minute,
            DateTime.now().second,
            DateTime.now().millisecond,
            DateTime.now().microsecond,
          ));
  List<ExampleModel> exampleList = [];
  @override
  void initState() {
    super.initState();
    exampleList = List.generate(
        _listOfDate.length,
        (index) => ExampleModel(
            message: "Message recived on ${_listOfDate[index]}",
            receiveTime: _listOfDate[index]));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: ListView(
            children: List.generate(
                exampleList.length,
                (index) => Container(
                      margin: const EdgeInsets.symmetric(vertical: 10),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(20),
                        color: Colors.grey.shade200,
                      ),
                      child: ListTile(
                        title: Text(
                          exampleList[index].message,
                          style: const TextStyle(color: Colors.black),
                        ),
                        trailing: Text(
                            DaysAgo(exampleList[index].receiveTime).getString),
                      ),
                    ))),
      ),
    );
  }
}

class ExampleModel {
  String message;
  DateTime receiveTime;
  ExampleModel({
    required this.message,
    required this.receiveTime,
  });
}
2
likes
130
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

Get time ago string, Just by passing Date and time.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on days_ago

Packages that implement days_ago