import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; import '../../globals.dart'; import '../../models/timeline_entry.dart'; import '../../services/timeline_manager.dart'; import '../../utils/snackbar_builder.dart'; class InteractionsBarControl extends StatefulWidget { final TimelineEntry entry; const InteractionsBarControl({super.key, required this.entry}); @override State createState() => _InteractionsBarControlState(); } class _InteractionsBarControlState extends State { static final _logger = Logger('$InteractionsBarControl'); bool get isFavorited => widget.entry.isFavorited; int get reshares => widget.entry.engagementSummary.rebloggedCount; int get comments => widget.entry.engagementSummary.repliesCount; int get likes => widget.entry.engagementSummary.favoritesCount; Future toggleFavorited() async { final newState = !isFavorited; _logger.finest('Trying to toggle favorite from $isFavorited to $newState'); final result = await getIt() .toggleFavorited(widget.entry.id, newState); result.match(onSuccess: (update) { setState(() { _logger.finest( 'Success toggling! $isFavorited -> ${update.entry.isFavorited}'); }); }, onError: (error) { buildSnackbar(context, 'Error toggling like status: $error'); }); } @override Widget build(BuildContext context) { _logger.finest('Building: ${widget.entry.toShortString()}'); return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('$likes likes, $reshares reshares, $comments comments'), IconButton( onPressed: () async => await toggleFavorited(), icon: isFavorited ? Icon(Icons.thumb_up) : Icon(Icons.thumb_up_outlined)), ], ); } }