buildAppBar method

PreferredSizeWidget buildAppBar({
  1. required BuildContext context,
  2. bool showFileNameBadge = false,
  3. bool showStats = false,
  4. bool showFilePicker = false,
  5. bool showReload = true,
  6. PreferredSizeWidget? bottom,
  7. bool? appBarPinned,
  8. ValueChanged<bool>? onAppBarPinnedChanged,
})

Build a standard AppBar with configurable components.

This method provides a consistent AppBar across different viewer implementations while allowing each to customize which features to show. Delegates to the shared SchematicAppBar widget.

Implementation

PreferredSizeWidget buildAppBar({
  required BuildContext context,
  bool showFileNameBadge = false,
  bool showStats = false,
  bool showFilePicker = false,
  bool showReload = true,
  PreferredSizeWidget? bottom,
  bool? appBarPinned,
  ValueChanged<bool>? onAppBarPinnedChanged,
}) {
  // Build the list of leading actions passed to SchematicAppBar.
  // Each action uses BlocBuilder internally when it needs theme info.
  final leadingActions = <Widget>[
    // Node/Edge count statistics
    if (showStats && layout != null)
      BlocBuilder<SchematicThemeCubit, SchematicThemeMode>(
        builder: (context, themeMode) {
          final isDark = themeMode == SchematicThemeMode.dark;
          return Container(
            padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
            decoration: BoxDecoration(
              color: isDark ? const Color(0xFF252526) : Colors.white,
              borderRadius: BorderRadius.circular(4),
            ),
            child: Text(
              'Modules: ${layout!.instances.length}  | '
              ' Signals: ${layout!.edges.length}',
              style: TextStyle(
                fontSize: 12,
                color: isDark ? Colors.white54 : Colors.black54,
              ),
            ),
          );
        },
      ),
    // File picker button
    if (showFilePicker)
      Tooltip(
        message: 'Open JSON file',
        child: MouseRegion(
          cursor: SystemMouseCursors.click,
          child: GestureDetector(
            onTap: loadSchematicFromFile,
            child: Padding(
              padding: const EdgeInsets.all(8),
              child: platformIcon(Icons.folder_open, '📁', size: 18),
            ),
          ),
        ),
      ),
    // Reload button
    if (showReload)
      Tooltip(
        message: 'Reload current schematic',
        child: MouseRegion(
          cursor: schematicJson != null
              ? SystemMouseCursors.click
              : MouseCursor.defer,
          child: GestureDetector(
            onTap: schematicJson != null ? handleReload : null,
            child: Padding(
              padding: const EdgeInsets.all(8),
              child: Opacity(
                opacity: schematicJson != null ? 1.0 : 0.5,
                child: platformIcon(Icons.refresh, '🔄', size: 18),
              ),
            ),
          ),
        ),
      ),
  ];

  return SchematicAppBar(
    fileName: showFileNameBadge ? fileName : null,
    leadingActions: leadingActions,
    crossProbeService: crossProbeService,
    bottom: bottom,
    appBarPinned: appBarPinned,
    onAppBarPinnedChanged: onAppBarPinnedChanged,
  );
}