import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../state.dart';
import 'device_avatar.dart';
import 'device_picker_dialog.dart';

class DeviceButton extends ConsumerWidget {
  final double radius;
  const DeviceButton({super.key, this.radius = 16});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final deviceNode = ref.watch(currentDeviceProvider);
    final deviceData = ref.watch(currentDeviceDataProvider);
    Widget deviceWidget;
    if (deviceNode != null) {
      if (deviceData != null) {
        deviceWidget = DeviceAvatar.yubiKeyData(
          deviceData,
          selected: true,
          radius: radius,
        );
      } else {
        deviceWidget = DeviceAvatar.deviceNode(
          deviceNode,
          selected: true,
          radius: radius,
        );
      }
    } else {
      deviceWidget = DeviceAvatar(
        radius: radius,
        child: const Icon(Icons.more_horiz),
      );
    }
    return Padding(
      padding: const EdgeInsets.only(right: 8.0),
      child: IconButton(
        tooltip: 'Select YubiKey or device',
        icon: OverflowBox(
          maxHeight: 44,
          maxWidth: 44,
          child: deviceWidget,
        ),
        onPressed: () {
          showDialog(
            context: context,
            builder: (context) => const DevicePickerDialog(),
          );
        },
      ),
    );
  }
}

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../state.dart';
import 'device_avatar.dart';
import 'device_picker_dialog.dart';

class DeviceButton extends ConsumerWidget {
  final double radius;
  const DeviceButton({super.key, this.radius = 16});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final deviceNode = ref.watch(currentDeviceProvider);
    final deviceData = ref.watch(currentDeviceDataProvider);
    Widget deviceWidget;
    if (deviceNode != null) {
      if (deviceData != null) {
        deviceWidget = DeviceAvatar.yubiKeyData(
          deviceData,
          selected: true,
          radius: radius,
        );
      } else {
        deviceWidget = DeviceAvatar.deviceNode(
          deviceNode,
          selected: true,
          radius: radius,
        );
      }
    } else {
      deviceWidget = DeviceAvatar(
        radius: radius,
        selected: true,
        child: const Icon(Icons.usb),
      );
    }
    return Padding(
      padding: const EdgeInsets.only(right: 8.0),
      child: IconButton(
        tooltip: 'Select YubiKey or device',
        icon: OverflowBox(
          maxHeight: 44,
          maxWidth: 44,
          child: deviceWidget,
        ),
        onPressed: () {
          showDialog(
            context: context,
            builder: (context) => const DevicePickerDialog(),
          );
        },
      ),
    );
  }
}

Use USB icon for no device when in USB mode.
Use USB icon for no device when in USB mode.
