// 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.
>Solution :
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.