Added call watch dialog

This commit is contained in:
2026-02-12 17:27:55 +01:00
parent a53cfb24ea
commit e4c0a23ded
9 changed files with 450 additions and 27 deletions

View File

@@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h"
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}

View File

@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$LocateDeviceRequestEntity {
String get deviceName; dynamic get command;
String get deviceName;
/// Create a copy of LocateDeviceRequestEntity
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -25,16 +25,16 @@ $LocateDeviceRequestEntityCopyWith<LocateDeviceRequestEntity> get copyWith => _$
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is LocateDeviceRequestEntity&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&const DeepCollectionEquality().equals(other.command, command));
return identical(this, other) || (other.runtimeType == runtimeType&&other is LocateDeviceRequestEntity&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName));
}
@override
int get hashCode => Object.hash(runtimeType,deviceName,const DeepCollectionEquality().hash(command));
int get hashCode => Object.hash(runtimeType,deviceName);
@override
String toString() {
return 'LocateDeviceRequestEntity(deviceName: $deviceName, command: $command)';
return 'LocateDeviceRequestEntity(deviceName: $deviceName)';
}
@@ -45,7 +45,7 @@ abstract mixin class $LocateDeviceRequestEntityCopyWith<$Res> {
factory $LocateDeviceRequestEntityCopyWith(LocateDeviceRequestEntity value, $Res Function(LocateDeviceRequestEntity) _then) = _$LocateDeviceRequestEntityCopyWithImpl;
@useResult
$Res call({
String deviceName, dynamic command
String deviceName
});
@@ -62,11 +62,10 @@ class _$LocateDeviceRequestEntityCopyWithImpl<$Res>
/// Create a copy of LocateDeviceRequestEntity
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? deviceName = null,Object? command = freezed,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? deviceName = null,}) {
return _then(_self.copyWith(
deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
as String,command: freezed == command ? _self.command : command // ignore: cast_nullable_to_non_nullable
as dynamic,
as String,
));
}
@@ -151,10 +150,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String deviceName, dynamic command)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String deviceName)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _LocateDeviceRequestEntity() when $default != null:
return $default(_that.deviceName,_that.command);case _:
return $default(_that.deviceName);case _:
return orElse();
}
@@ -172,10 +171,10 @@ return $default(_that.deviceName,_that.command);case _:
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String deviceName, dynamic command) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String deviceName) $default,) {final _that = this;
switch (_that) {
case _LocateDeviceRequestEntity():
return $default(_that.deviceName,_that.command);case _:
return $default(_that.deviceName);case _:
throw StateError('Unexpected subclass');
}
@@ -192,10 +191,10 @@ return $default(_that.deviceName,_that.command);case _:
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String deviceName, dynamic command)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String deviceName)? $default,) {final _that = this;
switch (_that) {
case _LocateDeviceRequestEntity() when $default != null:
return $default(_that.deviceName,_that.command);case _:
return $default(_that.deviceName);case _:
return null;
}
@@ -207,11 +206,10 @@ return $default(_that.deviceName,_that.command);case _:
class _LocateDeviceRequestEntity implements LocateDeviceRequestEntity {
const _LocateDeviceRequestEntity({required this.deviceName, this.command});
const _LocateDeviceRequestEntity({required this.deviceName});
@override final String deviceName;
@override final dynamic command;
/// Create a copy of LocateDeviceRequestEntity
/// with the given fields replaced by the non-null parameter values.
@@ -223,16 +221,16 @@ _$LocateDeviceRequestEntityCopyWith<_LocateDeviceRequestEntity> get copyWith =>
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LocateDeviceRequestEntity&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&const DeepCollectionEquality().equals(other.command, command));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _LocateDeviceRequestEntity&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName));
}
@override
int get hashCode => Object.hash(runtimeType,deviceName,const DeepCollectionEquality().hash(command));
int get hashCode => Object.hash(runtimeType,deviceName);
@override
String toString() {
return 'LocateDeviceRequestEntity(deviceName: $deviceName, command: $command)';
return 'LocateDeviceRequestEntity(deviceName: $deviceName)';
}
@@ -243,7 +241,7 @@ abstract mixin class _$LocateDeviceRequestEntityCopyWith<$Res> implements $Locat
factory _$LocateDeviceRequestEntityCopyWith(_LocateDeviceRequestEntity value, $Res Function(_LocateDeviceRequestEntity) _then) = __$LocateDeviceRequestEntityCopyWithImpl;
@override @useResult
$Res call({
String deviceName, dynamic command
String deviceName
});
@@ -260,11 +258,10 @@ class __$LocateDeviceRequestEntityCopyWithImpl<$Res>
/// Create a copy of LocateDeviceRequestEntity
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? deviceName = null,Object? command = freezed,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? deviceName = null,}) {
return _then(_LocateDeviceRequestEntity(
deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
as String,command: freezed == command ? _self.command : command // ignore: cast_nullable_to_non_nullable
as dynamic,
as String,
));
}

View File

@@ -1,6 +1,7 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:functions/src/features/functions/widgets/call_watch_dialog.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:utils/utils.dart';
@@ -95,9 +96,11 @@ class FunctionsScreen extends ConsumerWidget {
),
SizedBox(height: SizeUtils.getByScreen(small: 16, big: 15)),
AppSectionButton(
onPressed: (){},
icon: Icons.call_outlined,
text: 'Call watch'
onPressed: (){showDialog(context: context, builder: (context)=>Dialog(
child: CallWatchDialog()
));},
icon: Icons.call_outlined,
text: 'Call watch'
),
SizedBox(height: SizeUtils.getByScreen(small: 16, big: 15)),
AppSectionButton(
@@ -109,7 +112,7 @@ class FunctionsScreen extends ConsumerWidget {
AppSectionButton(
onPressed: (){},
icon: Icons.app_registration_sharp,
text: 'Apps supervision'
text: 'Apps surveillance'
),
SizedBox(height: SizeUtils.getByScreen(small: 16, big: 15)),
AppSectionButton(

View File

@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:functions/src/features/functions/state/call_watch_view_state.dart';
import 'package:url_launcher/url_launcher.dart';
final callWatchViewModelProvider =
NotifierProvider.autoDispose<CallWatchViewModel, CallWatchViewState>(
CallWatchViewModel.new,
);
class CallWatchViewModel extends Notifier<CallWatchViewState> {
late final TextEditingController phoneController;
static final RegExp _phoneRegex = RegExp(r'^\+?\d{6,15}$');
@override
CallWatchViewState build() {
phoneController = TextEditingController();
phoneController.addListener(_onPhoneChanged);
ref.onDispose(disposeControllers);
return const CallWatchViewState();
}
void _onPhoneChanged() {
final text = phoneController.text;
if (text == state.phone) return;
state = state.copyWith(phone: text, errorMessage: '');
}
void call() async {
final phone = state.phone;
if (phone.isEmpty){
state = state.copyWith(errorMessage: 'errorMessagePhoneIsEmpty');
return;
}
if (!_phoneRegex.hasMatch(phone)) {
state = state.copyWith(errorMessage: 'errorMessagePhoneIsInvalid');
return;
}
final url = Uri(scheme: 'tel', path: phone);
if (await canLaunchUrl(url)) {
launchUrl(url);
} else {
throw 'Could not launch $url';
}
}
void disposeControllers() {
phoneController.removeListener(_onPhoneChanged);
phoneController.dispose();
}
}

View File

@@ -0,0 +1,11 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'call_watch_view_state.freezed.dart';
@freezed
abstract class CallWatchViewState with _$CallWatchViewState {
const factory CallWatchViewState({
@Default('') String phone,
@Default('') String errorMessage,
}) = _CallWatchViewState;
}

View File

@@ -0,0 +1,274 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'call_watch_view_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$CallWatchViewState {
String get phone; String get errorMessage;
/// Create a copy of CallWatchViewState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$CallWatchViewStateCopyWith<CallWatchViewState> get copyWith => _$CallWatchViewStateCopyWithImpl<CallWatchViewState>(this as CallWatchViewState, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is CallWatchViewState&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,phone,errorMessage);
@override
String toString() {
return 'CallWatchViewState(phone: $phone, errorMessage: $errorMessage)';
}
}
/// @nodoc
abstract mixin class $CallWatchViewStateCopyWith<$Res> {
factory $CallWatchViewStateCopyWith(CallWatchViewState value, $Res Function(CallWatchViewState) _then) = _$CallWatchViewStateCopyWithImpl;
@useResult
$Res call({
String phone, String errorMessage
});
}
/// @nodoc
class _$CallWatchViewStateCopyWithImpl<$Res>
implements $CallWatchViewStateCopyWith<$Res> {
_$CallWatchViewStateCopyWithImpl(this._self, this._then);
final CallWatchViewState _self;
final $Res Function(CallWatchViewState) _then;
/// Create a copy of CallWatchViewState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? phone = null,Object? errorMessage = null,}) {
return _then(_self.copyWith(
phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [CallWatchViewState].
extension CallWatchViewStatePatterns on CallWatchViewState {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _CallWatchViewState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _CallWatchViewState() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _CallWatchViewState value) $default,){
final _that = this;
switch (_that) {
case _CallWatchViewState():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _CallWatchViewState value)? $default,){
final _that = this;
switch (_that) {
case _CallWatchViewState() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String phone, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _CallWatchViewState() when $default != null:
return $default(_that.phone,_that.errorMessage);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String phone, String errorMessage) $default,) {final _that = this;
switch (_that) {
case _CallWatchViewState():
return $default(_that.phone,_that.errorMessage);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String phone, String errorMessage)? $default,) {final _that = this;
switch (_that) {
case _CallWatchViewState() when $default != null:
return $default(_that.phone,_that.errorMessage);case _:
return null;
}
}
}
/// @nodoc
class _CallWatchViewState implements CallWatchViewState {
const _CallWatchViewState({this.phone = '', this.errorMessage = ''});
@override@JsonKey() final String phone;
@override@JsonKey() final String errorMessage;
/// Create a copy of CallWatchViewState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$CallWatchViewStateCopyWith<_CallWatchViewState> get copyWith => __$CallWatchViewStateCopyWithImpl<_CallWatchViewState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _CallWatchViewState&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,phone,errorMessage);
@override
String toString() {
return 'CallWatchViewState(phone: $phone, errorMessage: $errorMessage)';
}
}
/// @nodoc
abstract mixin class _$CallWatchViewStateCopyWith<$Res> implements $CallWatchViewStateCopyWith<$Res> {
factory _$CallWatchViewStateCopyWith(_CallWatchViewState value, $Res Function(_CallWatchViewState) _then) = __$CallWatchViewStateCopyWithImpl;
@override @useResult
$Res call({
String phone, String errorMessage
});
}
/// @nodoc
class __$CallWatchViewStateCopyWithImpl<$Res>
implements _$CallWatchViewStateCopyWith<$Res> {
__$CallWatchViewStateCopyWithImpl(this._self, this._then);
final _CallWatchViewState _self;
final $Res Function(_CallWatchViewState) _then;
/// Create a copy of CallWatchViewState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? phone = null,Object? errorMessage = null,}) {
return _then(_CallWatchViewState(
phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View File

@@ -0,0 +1,71 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:functions/src/features/functions/state/call_watch_view_model.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:utils/utils.dart';
class CallWatchDialog extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final viewModel = ref.read(callWatchViewModelProvider.notifier);
final viewState = ref.watch(callWatchViewModelProvider);
return Container(
padding: SizeUtils.getByScreen(
small: EdgeInsets.symmetric(horizontal: 26, vertical: 20),
big: EdgeInsets.symmetric(horizontal: 24, vertical: 18)
),
width: SizeUtils.getByScreen(small: 390, big: 380),
height: SizeUtils.getByScreen(small: 250, big: 243),
child: Column(
children: [
Stack(
children: [
Center(child: Text(context.translate('Call watch'),
textAlign: TextAlign.center,
style: TextStyle(fontSize: SizeUtils.getByScreen(small: 19, big: 18)),
)),
Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: (){Navigator.pop(context);},
icon: Icon(Icons.close, color: Color(0xFF588EA5)),
)
)
],
),
SizedBox(height: SizeUtils.getByScreen(small: 8, big: 7)),
CustomTextField(
controller: viewModel.phoneController,
hint: context.translate('Main contact phone number'),
keyboardType: TextInputType.number,
),
if (viewState.errorMessage.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 12),
child: Text(
viewState.errorMessage,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).colorScheme.error,
fontSize: 13,
),
),
),
SizedBox(height: SizeUtils.getByScreen(small: 28, big: 27)),
PrimaryButton(
onPressed: viewModel.call,
text: context.translate('Call me'),
color: Color(0xFF588EA5),
height: SizeUtils.getByScreen(small: 38, big: 36),
radius: SizeUtils.getByScreen(small: 32, big: 34),
),
],
),
);
}
}

View File

@@ -50,6 +50,7 @@ dependencies:
dio: ^5.9.0
json_annotation: ^4.9.0
json_serializable: ^6.11.2
url_launcher: ^6.3.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.