Browser-Tab-Manager/lib/widgets/app_bar_actions.dart

90 lines
No EOL
3.1 KiB
Dart

import 'package:flutter/material.dart';
class AppBarActions extends StatelessWidget {
final bool extensionMode;
final bool extensionConnected;
final bool isGridView;
final String sortBy;
final VoidCallback onStartTracking;
final VoidCallback onStopTracking;
final VoidCallback onRefresh;
final VoidCallback onToggleView;
final Function(String) onSortChanged;
const AppBarActions({
super.key,
required this.extensionMode,
required this.extensionConnected,
required this.isGridView,
required this.sortBy,
required this.onStartTracking,
required this.onStopTracking,
required this.onRefresh,
required this.onToggleView,
required this.onSortChanged,
});
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (extensionMode)
TextButton.icon(
onPressed: onStopTracking,
icon: const Icon(Icons.stop, color: Colors.white),
label: const Text('Stop', style: TextStyle(color: Colors.white)),
)
else
TextButton.icon(
onPressed: extensionConnected ? onStartTracking : null,
icon: const Icon(Icons.play_arrow, color: Colors.white),
label: const Text('Track Tabs', style: TextStyle(color: Colors.white)),
),
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: extensionMode ? null : onRefresh,
tooltip: 'Refresh',
),
IconButton(
icon: Icon(isGridView ? Icons.view_list : Icons.grid_view),
onPressed: onToggleView,
tooltip: isGridView ? 'List View' : 'Grid View',
),
PopupMenuButton<String>(
icon: const Icon(Icons.sort),
tooltip: 'Sort by',
onSelected: onSortChanged,
itemBuilder: (context) => [
const PopupMenuItem(value: 'recent', child: Text('Recent')),
const PopupMenuItem(value: 'title', child: Text('Title')),
const PopupMenuItem(value: 'url', child: Text('URL')),
const PopupMenuItem(value: 'visits', child: Text('Most Visited')),
],
),
],
);
}
}
// This widget displays all the action buttons in the top app bar.
//
// It is a stateless widget that receives all its data and callbacks from the parent.
//
// The Track Tabs button starts or stops extension tracking mode.
//
// The button changes from Track Tabs to Stop depending on whether extension mode is active.
//
// The refresh button reloads all data from the browser and is disabled during extension mode.
//
// The view toggle button switches between grid and list display layouts.
//
// The sort menu button opens a dropdown with sorting options like Recent, Title, URL, and Most Visited.
//
// All buttons trigger callbacks passed from the parent rather than handling logic themselves.
//
// This separation keeps the UI code clean and maintains a single source of truth in the parent widget.
//
// Extracting these actions into a separate widget makes the main screen code easier to read and maintain.