Skip to content

Commit

Permalink
don't update widget if not android
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastGimbus committed Sep 20, 2023
1 parent a747c2f commit b70e68e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import 'package:the_last_bluetooth/the_last_bluetooth.dart';
import 'headphones/cubit/headphones_connection_cubit.dart';
import 'headphones/cubit/headphones_mock_cubit.dart';

/// Small bool to say if we using real headphones or not
bool isMock = (!kIsWeb &&
Platform.isAndroid &&
!const bool.fromEnvironment('USE_HEADPHONES_MOCK'));

/// Gets real or fake connection cubit
HeadphonesConnectionCubit getHeadphonesCubit() => (!kIsWeb &&
Platform.isAndroid &&
!const bool.fromEnvironment('USE_HEADPHONES_MOCK'))
HeadphonesConnectionCubit getHeadphonesCubit() => isMock
? HeadphonesConnectionCubit(bluetooth: TheLastBluetooth.instance)
: HeadphonesMockCubit();
8 changes: 5 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ class _MyAppWrapperState extends State<MyAppWrapper>
// don't know if this is good place to put this, but seems right
// maybe convert this to multi listener with advanced "listenWhen" logic
// this would make it a nice single place to know what launches when 🤔
child: const BlocListener<HeadphonesConnectionCubit,
HeadphonesConnectionState>(
child:
BlocListener<HeadphonesConnectionCubit, HeadphonesConnectionState>(
listener: batteryHomeWidgetHearBloc,
child: MyApp(),
// Should this be *here* or somewhere special? Idk, okay for now 🤷
listenWhen: (p, c) => Platform.isAndroid,
child: const MyApp(),
),
),
);
Expand Down

0 comments on commit b70e68e

Please sign in to comment.