The class 'Jiffy' doesn't have an unnamed constructor. Try using one of the named constructors defined in 'Jiffy'

huangapple go评论76阅读模式
英文:

The class 'Jiffy' doesn't have an unnamed constructor. Try using one of the named constructors defined in 'Jiffy'

问题

你好朋友,你的代码如上所示。但是在"dateMessage: Jiffy(date).fromNow(),"这一行出现了错误,其中Jiffy出现了问题。如何解决这个错误呢?如果有人知道的话,如果你能通过对我的代码进行更改来显示错误的解决方案,我将不胜感激。

英文:
// ignore_for_file: unused_element

import 'package:faker/faker.dart';
import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart';

import '../../helpers.dart';
import '../models/models.dart';
import '../widgets/widgets.dart';

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

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        const SliverToBoxAdapter(
          child: _Stories(),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate(_delegate),
        ),
      ],
    );
  }

  Widget _delegate(BuildContext context, int index) {
    final Faker faker = Faker();
    final date = Helpers.randomDate();
    return _MessageTitle(
      messageData: MessageData(
        senderName: faker.person.name(),
        message: faker.lorem.sentence(),
        messageDate: date,
        dateMessage: Jiffy(date).fromNow(),
        profilePicture: Helpers.randomPictureUrl(),
      ),
    );
  }
}

class _MessageTitle extends StatelessWidget {
  const _MessageTitle({super.key, required this.messageData});

  final MessageData messageData;

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Card(
      // margin: const EdgeInsets.only(top: 8),
      elevation: 0,
      child: SizedBox(
        height: 134,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Padding(
              padding: EdgeInsets.only(
                left: 16.0,
                top: 8,
                bottom: 16,
              ),
              child: Text(
                "Stories",
                style: TextStyle(
                  fontWeight: FontWeight.w900,
                  fontSize: 15,
                  color: AppColors.textFaded,
                ),
              ),
            ),
            Expanded(
              child: ListView.builder(
                scrollDirection: Axis.horizontal,
                itemBuilder: (BuildContext context, int index) {
                  final faker = Faker();
                  return Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: SizedBox(
                      width: 60,
                      child: _StoryCard(
                        storyData: StoryData(
                          name: faker.person.name(),
                          url: Helpers.randomPictureUrl(),
                        ),
                      ),
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class _StoryCard extends StatelessWidget {
  const _StoryCard({
    Key? key,
    required this.storyData,
  }) : super(key: key);

  final StoryData storyData;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Avatar.medium(url: storyData.url),
        Expanded(
          child: Padding(
            padding: const EdgeInsets.only(top: 16.0),
            child: Text(
              storyData.name,
              overflow: TextOverflow.ellipsis,
              style: const TextStyle(
                fontSize: 11,
                letterSpacing: 0.3,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),
      ],
    );
  }
}

Hello friends, my codes are as you can see above. But "dateMessage: Jiffy(date).fromNow()," my code gives an error where Jiffy is. How is the solution to the error? If anyone knows, I would be very grateful if you show me the solution to the error by making changes to my codes.

Hello friends, my codes are as you can see above. But "dateMessage: Jiffy(date).fromNow()," my code gives an error where Jiffy is. How is the solution to the error? If anyone knows, I would be very grateful if you show me the solution to the error by making changes to my codes.

答案1

得分: 0

这行代码的语法错误:dateMessage: Jiffy(date).fromNow()

应该改成这样:Jiffy.parse('1997/09/23').fromNow(),在这里用你的 date 变量替换实际日期。

英文:

Your syntax is wrong in this line: dateMessage: Jiffy(date).fromNow()

It should be like this Jiffy.parse('1997/09/23').fromNow(), here replace the actual date with your date variable.

huangapple
  • 本文由 发表于 2023年7月6日 20:04:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定