Skip to content

Commit

Permalink
fix(connectivity_plus): Return valid connection type when only one av…
Browse files Browse the repository at this point in the history
…ailable (#2668)
  • Loading branch information
vbuberen committed Mar 10, 2024
1 parent f896d94 commit 81026a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
27 changes: 24 additions & 3 deletions packages/connectivity_plus/connectivity_plus/example/lib/main.dart
Expand Up @@ -92,11 +92,32 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Connectivity example app'),
title: const Text('Connectivity Plus Example'),
elevation: 4,
),
body: Center(
child: Text('Connection Status: ${_connectionStatus.toString()}')),
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Spacer(flex: 2),
Text(
'Active connection types:',
style: Theme.of(context).textTheme.headlineMedium,
),
const Spacer(),
ListView(
shrinkWrap: true,
children: List.generate(
_connectionStatus.length,
(index) => Center(
child: Text(
_connectionStatus[index].toString(),
style: Theme.of(context).textTheme.headlineSmall,
),
)),
),
const Spacer(flex: 2),
],
),
);
}
}
Expand Up @@ -29,7 +29,8 @@ class MethodChannelConnectivity extends ConnectivityPlatform {
Stream<List<ConnectivityResult>> get onConnectivityChanged {
_onConnectivityChanged ??= eventChannel
.receiveBroadcastStream()
.map((dynamic result) => List<String>.from(result))
.map((dynamic result) =>
result is String ? [result] : List<String>.from(result))
.map(parseConnectivityResults);
return _onConnectivityChanged!;
}
Expand Down

0 comments on commit 81026a4

Please sign in to comment.