[mob][cast] Return name and castDevice as record
This commit is contained in:
parent
89646ac469
commit
bd225ced04
11 changed files with 37 additions and 33 deletions
|
@ -4,22 +4,6 @@ import "package:ente_cast_normal/ente_cast_normal.dart";
|
|||
import "package:ente_feature_flag/ente_feature_flag.dart";
|
||||
import "package:shared_preferences/shared_preferences.dart";
|
||||
|
||||
CastService? _castService;
|
||||
CastService get castService {
|
||||
_castService ??= CastServiceImpl();
|
||||
return _castService!;
|
||||
}
|
||||
|
||||
FlagService? _flagService;
|
||||
|
||||
FlagService get flagService {
|
||||
_flagService ??= FlagService(
|
||||
ServiceLocator.instance.prefs,
|
||||
ServiceLocator.instance.enteDio,
|
||||
);
|
||||
return _flagService!;
|
||||
}
|
||||
|
||||
class ServiceLocator {
|
||||
late final SharedPreferences prefs;
|
||||
late final Dio enteDio;
|
||||
|
@ -34,3 +18,19 @@ class ServiceLocator {
|
|||
this.enteDio = enteDio;
|
||||
}
|
||||
}
|
||||
|
||||
FlagService? _flagService;
|
||||
|
||||
FlagService get flagService {
|
||||
_flagService ??= FlagService(
|
||||
ServiceLocator.instance.prefs,
|
||||
ServiceLocator.instance.enteDio,
|
||||
);
|
||||
return _flagService!;
|
||||
}
|
||||
|
||||
CastService? _castService;
|
||||
CastService get castService {
|
||||
_castService ??= CastServiceImpl();
|
||||
return _castService!;
|
||||
}
|
||||
|
|
|
@ -646,7 +646,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
}
|
||||
|
||||
Widget castWidget(BuildContext context) {
|
||||
return FutureBuilder<List<Object>>(
|
||||
return FutureBuilder<List<(String, Object)>>(
|
||||
future: castService.searchDevices(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
|
@ -666,7 +666,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
}
|
||||
|
||||
return Column(
|
||||
children: snapshot.data!.map((device) {
|
||||
children: snapshot.data!.map((result) {
|
||||
final device = result.$2;
|
||||
final name = result.$1;
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
try {
|
||||
|
@ -675,7 +677,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
showGenericErrorDialog(context: context, error: e).ignore();
|
||||
}
|
||||
},
|
||||
child: Text(device.toString()),
|
||||
child: Text(name),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
|
|
@ -1 +1 @@
|
|||
include: ../../analysis_options.yaml
|
||||
include: ../../analysis_options.yaml
|
||||
|
|
|
@ -2,6 +2,6 @@ import "package:flutter/widgets.dart";
|
|||
|
||||
abstract class CastService {
|
||||
bool get isSupported;
|
||||
Future<List<Object>> searchDevices();
|
||||
Future<List<(String, Object)>> searchDevices();
|
||||
Future<void> connectDevice(BuildContext context, Object device);
|
||||
}
|
||||
|
|
|
@ -16,4 +16,4 @@ dependencies:
|
|||
dev_dependencies:
|
||||
flutter_lints:
|
||||
|
||||
flutter:
|
||||
flutter:
|
||||
|
|
|
@ -1 +1 @@
|
|||
include: ../../analysis_options.yaml
|
||||
include: ../../analysis_options.yaml
|
||||
|
|
|
@ -8,10 +8,11 @@ class CastServiceImpl extends CastService {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<List<Object>> searchDevices() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
bool get isSupported => false;
|
||||
|
||||
@override
|
||||
bool get isSupported => false;
|
||||
Future<List<(String, Object)>> searchDevices() {
|
||||
// TODO: implement searchDevices
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,4 +15,4 @@ dependencies:
|
|||
dev_dependencies:
|
||||
flutter_lints:
|
||||
|
||||
flutter:
|
||||
flutter:
|
||||
|
|
|
@ -1 +1 @@
|
|||
include: ../../analysis_options.yaml
|
||||
include: ../../analysis_options.yaml
|
||||
|
|
|
@ -27,9 +27,10 @@ class CastServiceImpl extends CastService {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<List<Object>> searchDevices() {
|
||||
// TODO: implement searchDevices
|
||||
throw UnimplementedError();
|
||||
Future<List<(String, Object)>> searchDevices() {
|
||||
return CastDiscoveryService().search().then((devices) {
|
||||
return devices.map((device) => (device.name, device)).toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -19,4 +19,4 @@ dependencies:
|
|||
dev_dependencies:
|
||||
flutter_lints:
|
||||
|
||||
flutter:
|
||||
flutter:
|
||||
|
|
Loading…
Add table
Reference in a new issue