Backup before removing hiddify references
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hiddify/core/localization/translations.dart';
|
||||
@@ -16,7 +17,6 @@ import 'package:hiddify/gen/assets.gen.dart';
|
||||
import 'package:hiddify/utils/alerts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
// TODO: rewrite
|
||||
class ConnectionButton extends HookConsumerWidget {
|
||||
const ConnectionButton({super.key});
|
||||
|
||||
@@ -80,7 +80,7 @@ class ConnectionButton extends HookConsumerWidget {
|
||||
},
|
||||
buttonColor: switch (connectionStatus) {
|
||||
AsyncData(value: Connected()) when requiresReconnect == true => Colors.teal,
|
||||
AsyncData(value: Connected()) when delay <= 0 || delay >= 65000 => Color.fromARGB(255, 185, 176, 103),
|
||||
AsyncData(value: Connected()) when delay <= 0 || delay >= 65000 => const Color.fromARGB(255, 185, 176, 103),
|
||||
AsyncData(value: Connected()) => buttonTheme.connectedColor!,
|
||||
AsyncData(value: _) => buttonTheme.idleColor!,
|
||||
_ => Colors.red,
|
||||
@@ -90,20 +90,14 @@ class ConnectionButton extends HookConsumerWidget {
|
||||
AsyncData(value: Connected()) => Assets.images.connectNorouz,
|
||||
AsyncData(value: _) => Assets.images.disconnectNorouz,
|
||||
_ => Assets.images.disconnectNorouz,
|
||||
AsyncData(value: Disconnected()) || AsyncError() => Assets.images.disconnectNorouz,
|
||||
AsyncData(value: Connected()) => Assets.images.connectNorouz,
|
||||
_ => Assets.images.disconnectNorouz,
|
||||
},
|
||||
useImage: today.day >= 19 && today.day <= 23 && today.month == 3,
|
||||
isConnected: switch (connectionStatus) {
|
||||
AsyncData(value: Connected()) => true,
|
||||
_ => false,
|
||||
},
|
||||
useImage: true, // Всегда показывать картинки
|
||||
isConnected: connectionStatus is AsyncData && (connectionStatus as AsyncData).value is Connected,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ConnectionButton extends StatelessWidget {
|
||||
class _ConnectionButton extends StatefulWidget {
|
||||
const _ConnectionButton({
|
||||
required this.onTap,
|
||||
required this.enabled,
|
||||
@@ -122,62 +116,257 @@ class _ConnectionButton extends StatelessWidget {
|
||||
final bool useImage;
|
||||
final bool isConnected;
|
||||
|
||||
@override
|
||||
State<_ConnectionButton> createState() => _ConnectionButtonState();
|
||||
}
|
||||
|
||||
class _ConnectionButtonState extends State<_ConnectionButton> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _pulseController;
|
||||
bool _isPressed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pulseController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 2000),
|
||||
);
|
||||
|
||||
if (widget.isConnected) {
|
||||
_pulseController.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(_ConnectionButton oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.isConnected != oldWidget.isConnected) {
|
||||
if (widget.isConnected) {
|
||||
_pulseController.repeat();
|
||||
} else {
|
||||
_pulseController.stop();
|
||||
_pulseController.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pulseController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Semantics(
|
||||
button: true,
|
||||
enabled: enabled,
|
||||
label: label,
|
||||
child: Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
blurRadius: 16,
|
||||
color: buttonColor.withOpacity(0.5),
|
||||
enabled: widget.enabled,
|
||||
label: widget.label,
|
||||
child: GestureDetector(
|
||||
onTapDown: widget.enabled
|
||||
? (_) {
|
||||
HapticFeedback.lightImpact();
|
||||
setState(() => _isPressed = true);
|
||||
}
|
||||
: null,
|
||||
onTapUp: widget.enabled
|
||||
? (_) {
|
||||
setState(() => _isPressed = false);
|
||||
HapticFeedback.mediumImpact();
|
||||
widget.onTap();
|
||||
}
|
||||
: null,
|
||||
onTapCancel: () {
|
||||
setState(() => _isPressed = false);
|
||||
},
|
||||
child: AnimatedScale(
|
||||
scale: _isPressed ? 0.95 : 1.0,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
curve: Curves.easeOut,
|
||||
child: Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
// Основная тень
|
||||
BoxShadow(
|
||||
blurRadius: 32,
|
||||
spreadRadius: 0,
|
||||
color: widget.buttonColor.withOpacity(0.4),
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
// Внутренняя подсветка
|
||||
if (widget.isConnected)
|
||||
BoxShadow(
|
||||
blurRadius: 40,
|
||||
spreadRadius: -8,
|
||||
color: widget.buttonColor.withOpacity(0.6),
|
||||
offset: const Offset(0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// Pulse эффект при подключении
|
||||
if (widget.isConnected)
|
||||
AnimatedBuilder(
|
||||
animation: _pulseController,
|
||||
builder: (context, child) {
|
||||
return Container(
|
||||
width: 200 + (_pulseController.value * 20),
|
||||
height: 200 + (_pulseController.value * 20),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: widget.buttonColor.withOpacity(
|
||||
0.3 * (1 - _pulseController.value),
|
||||
),
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// Внешний круг с neomorphism эффектом
|
||||
Container(
|
||||
width: 200,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: isDark
|
||||
? [
|
||||
const Color(0xFF2C2C2C),
|
||||
const Color(0xFF1A1A1A),
|
||||
]
|
||||
: [
|
||||
const Color(0xFFF5F5F5),
|
||||
const Color(0xFFE0E0E0),
|
||||
],
|
||||
),
|
||||
boxShadow: [
|
||||
// Внешняя тень
|
||||
BoxShadow(
|
||||
color: isDark ? Colors.black.withOpacity(0.5) : Colors.grey.withOpacity(0.3),
|
||||
offset: const Offset(8, 8),
|
||||
blurRadius: 16,
|
||||
),
|
||||
// Внутренняя подсветка
|
||||
BoxShadow(
|
||||
color: isDark ? Colors.white.withOpacity(0.05) : Colors.white.withOpacity(0.8),
|
||||
offset: const Offset(-8, -8),
|
||||
blurRadius: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Внутренний круг с градиентом
|
||||
Container(
|
||||
width: 160,
|
||||
height: 160,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: RadialGradient(
|
||||
colors: [
|
||||
widget.buttonColor.withOpacity(0.95),
|
||||
widget.buttonColor,
|
||||
widget.buttonColor.withOpacity(1.0),
|
||||
],
|
||||
stops: const [0.0, 0.7, 1.0],
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: widget.buttonColor.withOpacity(0.5),
|
||||
blurRadius: 20,
|
||||
spreadRadius: -5,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
key: const ValueKey("home_connection_button"),
|
||||
shape: const CircleBorder(),
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: null, // Handled by GestureDetector
|
||||
splashColor: Colors.white.withOpacity(0.2),
|
||||
highlightColor: Colors.white.withOpacity(0.1),
|
||||
child: Center(
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(
|
||||
begin: 0.0,
|
||||
end: widget.isConnected ? 1.0 : 0.0,
|
||||
),
|
||||
duration: const Duration(milliseconds: 400),
|
||||
curve: Curves.easeInOut,
|
||||
builder: (context, value, child) {
|
||||
return Transform.rotate(
|
||||
angle: value * 0.5, // Легкий поворот при подключении
|
||||
child: Icon(
|
||||
Icons.power_settings_new_rounded,
|
||||
color: Colors.white,
|
||||
size: 72,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Glossy overlay эффект
|
||||
Positioned(
|
||||
top: 30,
|
||||
child: Container(
|
||||
width: 100,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.white.withOpacity(0.3),
|
||||
Colors.white.withOpacity(0.0),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
).animate(target: widget.enabled ? 0 : 1).blurXY(end: 2, curve: Curves.easeOut).animate(target: widget.enabled ? 0 : 1).scaleXY(end: 0.92, curve: Curves.easeInOut),
|
||||
),
|
||||
width: 120,
|
||||
height: 120,
|
||||
child: Material(
|
||||
key: const ValueKey("home_connection_button"),
|
||||
shape: const CircleBorder(),
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(30),
|
||||
child: TweenAnimationBuilder(
|
||||
tween: ColorTween(end: buttonColor),
|
||||
duration: const Duration(milliseconds: 250),
|
||||
builder: (context, value, child) {
|
||||
if (useImage) {
|
||||
return image.image(filterQuality: FilterQuality.medium);
|
||||
} else {
|
||||
// Определяем какую иконку показывать: play для отключенного, stop для подключенного
|
||||
return Icon(
|
||||
isConnected ? Icons.stop_rounded : Icons.play_arrow_rounded,
|
||||
color: value,
|
||||
size: 60,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
).animate(target: enabled ? 0 : 1).blurXY(end: 1),
|
||||
).animate(target: enabled ? 0 : 1).scaleXY(end: .88, curve: Curves.easeIn),
|
||||
),
|
||||
),
|
||||
const Gap(16),
|
||||
const Gap(28),
|
||||
ExcludeSemantics(
|
||||
child: AnimatedText(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
widget.label,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user