-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CameraSwith/SpeakerSwitch components.
- Loading branch information
1 parent
61b8708
commit 36b673d
Showing
6 changed files
with
212 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:livekit_client/livekit_client.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import '../../../context/media_device_context.dart'; | ||
import '../../../context/room_context.dart'; | ||
|
||
class CameraSwitch extends StatelessWidget { | ||
const CameraSwitch({ | ||
super.key, | ||
required this.builder, | ||
}); | ||
|
||
final Function(BuildContext context, RoomContext roomCtx, | ||
MediaDeviceContext deviceCtx, CameraPosition? position) builder; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Consumer<RoomContext>( | ||
builder: (context, roomCtx, child) { | ||
return Consumer<MediaDeviceContext>( | ||
builder: (context, deviceCtx, child) { | ||
return Selector<MediaDeviceContext, CameraPosition?>( | ||
selector: (context, position) => deviceCtx.currentPosition, | ||
builder: (context, position, child) => builder( | ||
context, | ||
roomCtx, | ||
deviceCtx, | ||
position, | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:provider/provider.dart'; | ||
|
||
import '../../../context/media_device_context.dart'; | ||
import '../../../context/room_context.dart'; | ||
|
||
class SpeakerSwitch extends StatelessWidget { | ||
const SpeakerSwitch({ | ||
super.key, | ||
required this.builder, | ||
}); | ||
|
||
final Function(BuildContext context, RoomContext roomCtx, | ||
MediaDeviceContext deviceCtx, bool? isSpeakerOn) builder; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Consumer<RoomContext>( | ||
builder: (context, roomCtx, child) { | ||
return Consumer<MediaDeviceContext>( | ||
builder: (context, deviceCtx, child) { | ||
return Selector<MediaDeviceContext, bool?>( | ||
selector: (context, isSpeakerOn) => deviceCtx.isSpeakerOn, | ||
builder: (context, isSpeakerOn, child) => builder( | ||
context, | ||
roomCtx, | ||
deviceCtx, | ||
isSpeakerOn, | ||
), | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:livekit_client/livekit_client.dart'; | ||
|
||
class CameraSwitchButton extends StatelessWidget { | ||
const CameraSwitchButton({ | ||
super.key, | ||
this.currentPosition = CameraPosition.front, | ||
this.onToggle, | ||
this.disabled = false, | ||
}); | ||
|
||
final CameraPosition? currentPosition; | ||
final Function(CameraPosition position)? onToggle; | ||
final bool disabled; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
style: ButtonStyle( | ||
backgroundColor: WidgetStateProperty.all(Colors.grey.withOpacity(0.6)), | ||
foregroundColor: WidgetStateProperty.all(Colors.white), | ||
overlayColor: WidgetStateProperty.all(Colors.grey), | ||
shape: WidgetStateProperty.all(const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(20.0)))), | ||
padding: WidgetStateProperty.all( | ||
const EdgeInsets.all(12), | ||
), | ||
), | ||
onPressed: () => onToggle?.call(currentPosition == CameraPosition.front | ||
? CameraPosition.back | ||
: CameraPosition.front), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon(currentPosition == CameraPosition.back | ||
? Icons.video_camera_back | ||
: Icons.video_camera_front), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class SpeakerSwitchButton extends StatelessWidget { | ||
const SpeakerSwitchButton({ | ||
super.key, | ||
this.isSpeakerOn = false, | ||
this.onToggle, | ||
this.disabled = false, | ||
}); | ||
|
||
final bool isSpeakerOn; | ||
final Function(bool speakerOn)? onToggle; | ||
final bool disabled; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
style: ButtonStyle( | ||
backgroundColor: WidgetStateProperty.all(Colors.grey.withOpacity(0.6)), | ||
foregroundColor: WidgetStateProperty.all(Colors.white), | ||
overlayColor: WidgetStateProperty.all(Colors.grey), | ||
shape: WidgetStateProperty.all(const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(20.0)))), | ||
padding: WidgetStateProperty.all(const EdgeInsets.all(12)), | ||
), | ||
onPressed: () => onToggle?.call(!isSpeakerOn), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon(isSpeakerOn ? Icons.speaker_phone : Icons.phone_android), | ||
], | ||
), | ||
); | ||
} | ||
} |