import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../../globals.dart'; import '../../models/connection.dart'; import '../../models/timeline_entry.dart'; import '../../routes.dart'; import '../../services/connections_manager.dart'; import '../../utils/dateutils.dart'; import '../../utils/url_opening_utils.dart'; import '../padding.dart'; class StatusHeaderControl extends StatelessWidget { final TimelineEntry entry; final bool openRemote; final bool showOpenControl; const StatusHeaderControl( {super.key, required this.entry, required this.openRemote, required this.showOpenControl}); void goToProfile(BuildContext context) { context.pushNamed(ScreenPaths.userProfile, params: {'id': entry.authorId}); } @override Widget build(BuildContext context) { final author = getIt() .getById(entry.authorId) .getValueOrElse(() => Connection()); return Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( onTap: () => goToProfile(context), child: CachedNetworkImage( imageUrl: author.avatarUrl.toString(), width: 32.0, ), ), const HorizontalPadding(), Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( onTap: () => goToProfile(context), child: Text( author.name, style: Theme.of(context).textTheme.bodyText1, ), ), Row( children: [ Text( ElapsedDateUtils.epochSecondsToString( entry.backdatedTimestamp), style: Theme.of(context).textTheme.caption, ), const HorizontalPadding(), Icon( entry.isPublic ? Icons.public : Icons.lock, color: Theme.of(context).hintColor, size: Theme.of(context).textTheme.caption?.fontSize, ), ], ), // Text( // entry.id, // ), ], ), if (showOpenControl) ...[ const Expanded(child: SizedBox()), buildActionBar(context), ], ], ); } Widget buildActionBar(BuildContext context) { return Row( children: [ IconButton( onPressed: () async { await _openAction(context); }, icon: const Icon(Icons.launch), ), ], ); } Future _openAction(BuildContext context) async { if (openRemote) { final openInBrowser = await showYesNoDialog(context, 'Open in external browser?'); if (openInBrowser == true) { await openUrlStringInSystembrowser(context, entry.externalLink, 'Post'); } } else { context.push('/post/view/${entry.id}'); } } }