Skip to content

Commit

Permalink
chore(dogfooding): added registered devices list to dogfooding app (#833
Browse files Browse the repository at this point in the history
)

* added registered devices list to dogfooding

* tweaks

---------

Co-authored-by: Deven Joshi <[email protected]>
  • Loading branch information
Brazol and deven98 authored Jan 21, 2025
1 parent b3738a7 commit d6bf385
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dogfooding/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import '../di/injector.dart';
import '../utils/assets.dart';
import '../utils/consts.dart';
import '../utils/loading_dialog.dart';
import '../widgets/user_actions_avatar.dart';

class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
Expand Down Expand Up @@ -196,9 +197,8 @@ class _HomeScreenState extends State<HomeScreen> {
appBar: AppBar(
elevation: 0,
backgroundColor: theme.scaffoldBackgroundColor,
leading: Padding(
padding: const EdgeInsets.all(8),
child: StreamUserAvatar(user: currentUser),
leading: UserActionsAvatar(
currentUser: currentUser,
),
titleSpacing: 4,
centerTitle: false,
Expand Down
75 changes: 75 additions & 0 deletions dogfooding/lib/widgets/device_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:stream_video_flutter/stream_video_flutter.dart';

class DeviceList extends StatefulWidget {
const DeviceList({
required this.devices,
super.key,
});

final List<PushDevice> devices;

@override
State<DeviceList> createState() => _DeviceListState();
}

class _DeviceListState extends State<DeviceList> {
List<PushDevice> devices = [];

@override
void initState() {
devices = widget.devices;
super.initState();
}

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: devices
.map(
(e) => Row(
children: [
IconButton(
onPressed: () async {
await StreamVideo.instance.removeDevice(
pushToken: e.pushToken,
);

setState(() {
devices.remove(e);
});
},
icon: const Icon(
Icons.delete,
color: Colors.red,
),
),
Expanded(
child: ListTile(
title: Text(e.pushProvider.name),
subtitle: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Text(e.userId ?? '')),
if (e.voip == true) ...[
const Icon(
Icons.phone,
size: 16,
),
const SizedBox(width: 4),
const Text('VOIP'),
],
],
),
),
),
],
),
)
.toList(),
),
);
}
}
90 changes: 90 additions & 0 deletions dogfooding/lib/widgets/user_actions_avatar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:flutter/material.dart';
import 'package:flutter_dogfooding/widgets/device_list.dart';
import 'package:stream_video_flutter/stream_video_flutter.dart';

import '../theme/app_palette.dart';

class UserActionsAvatar extends StatelessWidget {
const UserActionsAvatar({
required this.currentUser,
super.key,
});

final UserInfo currentUser;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: MenuAnchor(
style: const MenuStyle(
alignment: Alignment.bottomRight,
padding: WidgetStatePropertyAll(EdgeInsets.all(8)),
backgroundColor:
WidgetStatePropertyAll(AppColorPalette.buttonSecondary),
),
alignmentOffset: const Offset(00, 0),
builder: (
BuildContext context,
MenuController controller,
Widget? child,
) {
return InkWell(
onTap: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
child: StreamUserAvatar(user: currentUser),
);
},
menuChildren: [
MenuItemButton(
child: const Text(
'List devices',
style: TextStyle(color: Colors.white),
),
onPressed: () async {
final devices = await StreamVideo.instance.getDevices();

showDialog(
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return AlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Devices'),
IconButton(
onPressed: () async {
for (final device in devices.getDataOrNull()!) {
await StreamVideo.instance
.removeDevice(pushToken: device.pushToken);
}

// ignore: use_build_context_synchronously
Navigator.of(context).pop();
},
icon: const Icon(
Icons.delete,
color: Colors.red,
),
)
],
),
content: DeviceList(
devices: devices.getDataOrNull()!,
),
);
},
);
},
),
],
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ extension DeviceExt on open.DeviceResponse {
pushToken: id,
pushProvider: parsedProvider,
pushProviderName: pushProviderName,
userId: userId,
voip: voip,
createdAt: createdAt,
disabled: disabled,
Expand Down
4 changes: 4 additions & 0 deletions packages/stream_video/lib/src/models/push_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PushDevice with EquatableMixin {
required this.pushToken,
required this.pushProvider,
this.pushProviderName,
this.userId,
this.voip,
required this.createdAt,
this.disabled,
Expand All @@ -24,6 +25,9 @@ class PushDevice with EquatableMixin {
/// The notification push provider name
final String? pushProviderName;

/// The user id associated with the device
final String? userId;

/// When true the token is for Apple VoIP push notifications
final bool? voip;

Expand Down

0 comments on commit d6bf385

Please sign in to comment.