diff options
author | uvok | 2025-07-30 13:41:24 +0200 |
---|---|---|
committer | uvok | 2025-07-30 13:41:24 +0200 |
commit | 5e1ec6faca3f89cfb96918c48cb2b1deccac65c5 (patch) | |
tree | 26d90962df0839ce93f19d3b0df87962ee2281d8 /lib/control | |
parent | a5696a551577293f7afd4986119dd2d6636b1fdf (diff) |
Add mock scanner controller
Diffstat (limited to 'lib/control')
-rw-r--r-- | lib/control/mock_scanner_controller.dart | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/control/mock_scanner_controller.dart b/lib/control/mock_scanner_controller.dart new file mode 100644 index 0000000..41ec622 --- /dev/null +++ b/lib/control/mock_scanner_controller.dart @@ -0,0 +1,49 @@ +import 'dart:async'; + +import 'package:badge/control/scanner_controller.dart'; +import 'package:badge/control/scanner_controller_impl.dart'; +import 'package:badge/model/device.dart'; +import 'package:badge/model/mock_device.dart'; + +class MockScannerController extends ScannerControllerImpl { + static final List<MockDevice> fakedDevices = [ + MockDevice(0, "First"), + MockDevice(1, "Second"), + MockDevice(2, "Third"), + MockDevice(3, "Fourth"), + ]; + + @override + void dispose() {} + + @override + Stream<List<Device>> get scanResultsStream => _deviceContoller.stream; + final StreamController<List<Device>> _deviceContoller = + StreamController<List<Device>>.broadcast(); + + bool _isScanning = false; + + @override + Future<void> startScan({ + Duration timeout = const Duration(seconds: 2), + }) async { + if (_isScanning) return; + _isScanning = true; + setStatus(ScanStatus.scanning); + + for (int i = 0; i < fakedDevices.length && _isScanning; i++) { + await Future.delayed(Duration(milliseconds: 300)); + _deviceContoller.add( + fakedDevices.getRange(0, i + 1).toList(growable: false), + ); + } + + _isScanning = false; + setStatus(ScanStatus.finished); + } + + @override + Future<void> stopScan() async { + _isScanning = false; + } +} |