8557a46d05
* Add autoConnect support * Enhance autoConnect functionality for Bluetooth devices - Added support for managing a set of auto-connect devices in both Android and iOS implementations. - Updated connection and disconnection logic to handle auto-reconnect scenarios appropriately. - Improved cleanup processes to prevent unwanted reconnections when devices are manually disconnected. * Refactor connection button and add auto-reconnect toggle - Updated the connection button layout for better UI consistency. - Introduced an auto-reconnect toggle to manage automatic reconnections when devices become available. - Enhanced connection and disconnection logic to respect the auto-connect setting. * Update version to 1.2.0 and add CHANGELOG for new features - Bumped version to 1.2.0. - Added CHANGELOG.md detailing new features including support for `autoConnect` and UI updates for automatic reconnection. * Improve readme * Refactor variable naming for clarity in Bluetooth connection logic - Changed variable name from `isAutoConnect` to `shouldAutoConnect` for better readability and understanding of its purpose in the connection state handling. * Refactor connection handling in UniversalBlePlugin - Simplified connection logic by always cleaning up internal state before sending connection change callbacks. - Ensured GATT resources are only closed when autoConnect is disabled, allowing for better management of Bluetooth connections. * Refactor disconnection handling in UniversalBlePlugin - Introduced a new method `handlePeripheralDisconnection` to encapsulate disconnection logic, improving code readability and maintainability. - Updated the `centralManager` methods to utilize the new disconnection handler, ensuring consistent behavior across connection state changes. * Update darwin/Classes/UniversalBlePlugin.swift Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Foti Dim <fotios.dimanidis@a2zebra.de> Co-authored-by: Navideck Labs <130186950+navidecklabs@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
56 lines
1.6 KiB
Dart
56 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:universal_ble/universal_ble.dart';
|
|
import 'package:universal_ble_example/data/storage_service.dart';
|
|
import 'package:universal_ble_example/home/permission_screen.dart';
|
|
import 'package:universal_ble_example/home/scanner_screen.dart';
|
|
|
|
/// Initializes the app services and checks permissions.
|
|
/// Returns whether the app has the required permissions.
|
|
Future<bool> initializeApp() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await StorageService.instance.init();
|
|
await UniversalBle.setLogLevel(BleLogLevel.verbose);
|
|
return await UniversalBle.hasPermissions(
|
|
withAndroidFineLocation: false,
|
|
);
|
|
}
|
|
|
|
class UniversalBleApp extends StatelessWidget {
|
|
final bool hasPermission;
|
|
final Locale? locale;
|
|
final Widget Function(BuildContext, Widget?)? builder;
|
|
|
|
const UniversalBleApp({
|
|
super.key,
|
|
required this.hasPermission,
|
|
this.locale,
|
|
this.builder,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Universal BLE',
|
|
debugShowCheckedModeBanner: false,
|
|
locale: locale,
|
|
builder: builder,
|
|
theme: ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: Colors.blue,
|
|
brightness: Brightness.light,
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
useMaterial3: true,
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: Colors.blue,
|
|
brightness: Brightness.dark,
|
|
),
|
|
),
|
|
themeMode: ThemeMode.system,
|
|
home: hasPermission ? ScannerScreen() : const PermissionScreen(),
|
|
);
|
|
}
|
|
}
|