ehharvey / conglobo

1 stars 0 forks source link

Desktop App to produce Autoinstall USB #33

Open ehharvey opened 1 year ago

ehharvey commented 1 year ago

(): optional goal

See desktop app workflow for more details

7zip in flutter

USB management in flutter

Gabeele commented 1 year ago

It's not possible to directly detect whether a USB drive has a particular operating system or ISO installed through Flutter, as Flutter is a framework for building user interfaces and doesn't have direct access to the underlying system.

However, you can detect whether a USB drive is connected and retrieve information about its name, path, and storage capacity using the flutter_usb_detector package. Here's an example of how you could use it:

First, add flutter_usb_detector to your pubspec.yaml file:

yaml

dependencies:
  flutter_usb_detector: ^1.0.0

Then, import the package and use the FlutterUsbDetector class to detect connected USB drives and retrieve information about them:

dart

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

class UsbDetectorPage extends StatefulWidget {
  @override
  _UsbDetectorPageState createState() => _UsbDetectorPageState();
}

class _UsbDetectorPageState extends State<UsbDetectorPage> {
  List<UsbDevice> devices = [];

  @override
  void initState() {
    super.initState();
    FlutterUsbDetector().startListening(onDeviceDetected);
  }

  @override
  void dispose() {
    FlutterUsbDetector().stopListening();
    super.dispose();
  }

  void onDeviceDetected(UsbDevice device) {
    setState(() {
      devices.add(device);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('USB Detector'),
      ),
      body: ListView.builder(
        itemCount: devices.length,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(devices[index].name),
            subtitle: Text('Capacity: ${devices[index].capacity}'),
            trailing: Icon(Icons.usb),
          );
        },
      ),
    );
  }
}

This code sets up a ListView that displays the names and capacities of connected USB drives, and adds any detected drives to the devices list. When a USB drive is connected, the onDeviceDetected function is called with a UsbDevice object that contains information about the drive, including its name, path, and capacity.

To check whether a particular USB drive contains a Ubuntu ISO, you would need to inspect the contents of the drive programmatically. One way to do this would be to use the dart:io library to search for files with a particular name or extension, such as ubuntu.iso. However, keep in mind that this would not guarantee that the file found is actually a valid Ubuntu ISO or that it has been installed correctly.