158 lines
6.2 KiB
Dart
158 lines
6.2 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';
|
|
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/models/home_page_content/swot.dart';
|
|
import 'package:didvan/services/app_initalizer.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/views/home/main/widgets/bookmark.dart';
|
|
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
class SwotItemCard extends StatefulWidget {
|
|
final SwotItem item;
|
|
|
|
const SwotItemCard({super.key, required this.item, this.onBookmarkChangedInList});
|
|
final void Function(int postId, bool isBookmarked)? onBookmarkChangedInList;
|
|
|
|
@override
|
|
State<SwotItemCard> createState() => _SwotItemCardState();
|
|
}
|
|
|
|
class _SwotItemCardState extends State<SwotItemCard> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
AppInitializer.openWebLink(
|
|
context,
|
|
'http://opportunity-threat.didvan.com/posts/${widget.item.id}/?accessToken=${RequestService.token}',
|
|
mode: LaunchMode.inAppWebView,
|
|
);
|
|
},
|
|
child: Container(
|
|
width: 250,
|
|
height: 50,
|
|
margin: const EdgeInsets.only(right: 0),
|
|
padding: const EdgeInsets.all(0),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).cardColor,
|
|
borderRadius: BorderRadius.circular(9),
|
|
),
|
|
child: Stack(
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(12),
|
|
topRight: Radius.circular(12),
|
|
),
|
|
child: CachedNetworkImage(
|
|
errorWidget: (context, url, error) {
|
|
if (kDebugMode) {
|
|
print('image fetch complete with Error: $error');
|
|
}
|
|
return Container(
|
|
height: 150,
|
|
width: 300,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
Theme.of(context).colorScheme.disabledBackground,
|
|
),
|
|
child: const Icon(Icons.image_not_supported_outlined),
|
|
);
|
|
},
|
|
errorListener: (value) {},
|
|
fit: BoxFit.cover,
|
|
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
|
|
httpHeaders: {
|
|
'Authorization': 'Bearer ${RequestService.token}'
|
|
},
|
|
width: 300,
|
|
height: 150,
|
|
imageUrl: widget.item.imageUrl,
|
|
placeholder: (context, _) => const ShimmerPlaceholder(
|
|
width: 300,
|
|
height: 150,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
widget.item.title,
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
widget.item.type == "THREAT"
|
|
? SvgPicture.asset(
|
|
"lib/assets/images/features/Badge.svg")
|
|
: SvgPicture.asset(
|
|
"lib/assets/images/features/Badge-Green.svg"),
|
|
const SizedBox(
|
|
width: 5,
|
|
),
|
|
Text(
|
|
widget.item.type == "THREAT" ? "تهدید" : "فرصت",
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 10,
|
|
),
|
|
Row(
|
|
children: [
|
|
SvgPicture.asset(
|
|
"lib/assets/images/features/ant-design_dot-chart-outlined.svg"),
|
|
const SizedBox(
|
|
width: 5,
|
|
),
|
|
Text(
|
|
'عدد ${widget.item.type == "THREAT" ? "تهدید" : "فرصت"}: ${((widget.item.x1 ?? 0.0) * (widget.item.y1 ?? 0.0)).toStringAsFixed(1)}',
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
)
|
|
],
|
|
),
|
|
// GestureDetector(
|
|
// onTap: () {}, child: Icon(DidvanIcons.bookmark_solid)
|
|
// // Icon(
|
|
// // widget.item.marked
|
|
// // ? DidvanIcons.bookmark_solid
|
|
// // : DidvanIcons.bookmark_regular,
|
|
// // color: widget.item.marked
|
|
// // ? Theme.of(context).colorScheme.secondary
|
|
// // : Theme.of(context).colorScheme.caption,
|
|
// // ),
|
|
// ),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Positioned(
|
|
bottom: 0,
|
|
left: 0,
|
|
child: BookmarkIcon(postId: widget.item.id),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|