Skip to content

Commit a66cada

Browse files
committed
Refactor onboarding screen and improve code formatting
- Added .env file to pubspec.yaml for environment configuration. - Simplified the OnboardingScreen constructor for better readability. - Enhanced code formatting in onboarding_screen.dart for consistency. - Improved main.dart routing for onboarding screen. - Cleaned up unnecessary whitespace in various service files.
1 parent a32547e commit a66cada

7 files changed

Lines changed: 103 additions & 102 deletions

File tree

lib/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ class App extends StatelessWidget {
9999
home: homeScreen,
100100
routes: {
101101
'/': (context) => const MainScreen(),
102-
'/onboarding': (context) => OnboardingScreen(
103-
onboardingService: onboardingService,
104-
),
102+
'/onboarding': (context) =>
103+
OnboardingScreen(onboardingService: onboardingService),
105104
},
106105
localizationsDelegates: const [
107106
AppLocalizations.delegate,

lib/pages/onboarding/onboarding_screen.dart

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import '../../services/config_service.dart';
55

66
class OnboardingScreen extends StatefulWidget {
77
final OnboardingService onboardingService;
8-
9-
const OnboardingScreen({
10-
super.key,
11-
required this.onboardingService,
12-
});
8+
9+
const OnboardingScreen({super.key, required this.onboardingService});
1310

1411
@override
1512
State<OnboardingScreen> createState() => _OnboardingScreenState();
@@ -21,28 +18,28 @@ class _OnboardingScreenState extends State<OnboardingScreen>
2118
late Animation<double> _fadeAnimation;
2219
late Animation<double> _slideAnimation;
2320
int _currentStep = 0;
24-
21+
2522
List<OnboardingStep> _getSteps() {
2623
return [
2724
// Шаг 1: Подключение к телеграм боту
2825
OnboardingStep(
2926
title: 'Welcome',
30-
description: ConfigService.requiresTelegramBot
31-
? 'To connect, go to the telegram bot to get your unique subscription'
32-
: 'To connect, go to the telegram bot (optional)',
27+
description: ConfigService.requiresTelegramBot
28+
? 'To connect, go to the telegram bot to get your unique subscription'
29+
: 'To connect, go to the telegram bot (optional)',
3330
telegramBot: '@${ConfigService.telegramBotUsername}',
3431
icon: Icons.telegram,
3532
color: const Color(0xFF0088CC),
3633
showSkip: ConfigService.canSkipOnboarding,
3734
isWelcome: true,
3835
),
39-
36+
4037
// Шаг 2: Настройки успешно получены
4138
OnboardingStep(
4239
title: 'Settings Received',
4340
description: ConfigService.requiresTelegramBot
44-
? 'Your unique subscription has been successfully received'
45-
: 'Your settings have been successfully received',
41+
? 'Your unique subscription has been successfully received'
42+
: 'Your settings have been successfully received',
4643
icon: Icons.check_circle,
4744
color: const Color(0xFF4CAF50),
4845
isLast: true,
@@ -58,22 +55,14 @@ class _OnboardingScreenState extends State<OnboardingScreen>
5855
duration: const Duration(milliseconds: 800),
5956
vsync: this,
6057
);
61-
_fadeAnimation = Tween<double>(
62-
begin: 0.0,
63-
end: 1.0,
64-
).animate(CurvedAnimation(
65-
parent: _animationController,
66-
curve: Curves.easeInOut,
67-
));
68-
_slideAnimation = Tween<double>(
69-
begin: 0.8,
70-
end: 1.0,
71-
).animate(CurvedAnimation(
72-
parent: _animationController,
73-
curve: Curves.easeInOut,
74-
));
58+
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
59+
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
60+
);
61+
_slideAnimation = Tween<double>(begin: 0.8, end: 1.0).animate(
62+
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
63+
);
7564
_animationController.forward();
76-
65+
7766
// Слушаем изменения в onboarding сервисе для обработки deep links
7867
widget.onboardingService.addListener(_onOnboardingChanged);
7968
}
@@ -137,12 +126,18 @@ class _OnboardingScreenState extends State<OnboardingScreen>
137126
final botUrl = ConfigService.telegramBotFullUrl;
138127
try {
139128
if (await canLaunchUrl(Uri.parse(botUrl))) {
140-
await launchUrl(Uri.parse(botUrl), mode: LaunchMode.externalApplication);
129+
await launchUrl(
130+
Uri.parse(botUrl),
131+
mode: LaunchMode.externalApplication,
132+
);
141133
} else {
142134
// Fallback to web browser
143135
final webUrl = ConfigService.telegramBotWebUrl;
144136
if (await canLaunchUrl(Uri.parse(webUrl))) {
145-
await launchUrl(Uri.parse(webUrl), mode: LaunchMode.externalApplication);
137+
await launchUrl(
138+
Uri.parse(webUrl),
139+
mode: LaunchMode.externalApplication,
140+
);
146141
}
147142
}
148143
} catch (e) {
@@ -154,18 +149,14 @@ class _OnboardingScreenState extends State<OnboardingScreen>
154149
Widget build(BuildContext context) {
155150
final steps = _getSteps();
156151
final currentStepData = steps[_currentStep];
157-
152+
158153
return Scaffold(
159154
body: Container(
160155
decoration: const BoxDecoration(
161156
gradient: LinearGradient(
162157
begin: Alignment.topCenter,
163158
end: Alignment.bottomCenter,
164-
colors: [
165-
Colors.white,
166-
Color(0xFFF8F9FA),
167-
Color(0xFFE9ECEF),
168-
],
159+
colors: [Colors.white, Color(0xFFF8F9FA), Color(0xFFE9ECEF)],
169160
),
170161
),
171162
child: SafeArea(
@@ -178,13 +169,15 @@ class _OnboardingScreenState extends State<OnboardingScreen>
178169
child: Padding(
179170
padding: const EdgeInsets.all(20),
180171
child: TextButton(
181-
onPressed: ConfigService.canSkipOnboarding ? _skipOnboarding : null,
172+
onPressed: ConfigService.canSkipOnboarding
173+
? _skipOnboarding
174+
: null,
182175
child: Text(
183176
'Skip',
184177
style: TextStyle(
185-
color: ConfigService.canSkipOnboarding
186-
? const Color(0xFF6C757D)
187-
: const Color(0xFF6C757D).withOpacity(0.3),
178+
color: ConfigService.canSkipOnboarding
179+
? const Color(0xFF6C757D)
180+
: const Color(0xFF6C757D).withOpacity(0.3),
188181
fontSize: 16,
189182
fontWeight: FontWeight.w500,
190183
),
@@ -193,7 +186,7 @@ class _OnboardingScreenState extends State<OnboardingScreen>
193186
),
194187
),
195188
],
196-
189+
197190
// Main content
198191
Expanded(
199192
child: Padding(
@@ -207,7 +200,7 @@ class _OnboardingScreenState extends State<OnboardingScreen>
207200
),
208201
),
209202
),
210-
203+
211204
// Navigation buttons
212205
Container(
213206
padding: const EdgeInsets.all(20),
@@ -244,7 +237,9 @@ class _OnboardingScreenState extends State<OnboardingScreen>
244237
],
245238
Expanded(
246239
child: ElevatedButton(
247-
onPressed: currentStepData.isWelcome ? _openTelegramBot : _nextStep,
240+
onPressed: currentStepData.isWelcome
241+
? _openTelegramBot
242+
: _nextStep,
248243
style: ElevatedButton.styleFrom(
249244
backgroundColor: currentStepData.color,
250245
foregroundColor: Colors.white,
@@ -257,17 +252,23 @@ class _OnboardingScreenState extends State<OnboardingScreen>
257252
mainAxisAlignment: MainAxisAlignment.center,
258253
children: [
259254
Text(
260-
currentStepData.isWelcome
261-
? (ConfigService.requiresTelegramBot
262-
? 'Go to telegram bot'
263-
: 'Go to telegram bot (optional)')
264-
: (currentStepData.isLast ? 'Get Started' : 'Next'),
255+
currentStepData.isWelcome
256+
? (ConfigService.requiresTelegramBot
257+
? 'Go to telegram bot'
258+
: 'Go to telegram bot (optional)')
259+
: (currentStepData.isLast
260+
? 'Get Started'
261+
: 'Next'),
265262
style: const TextStyle(
266263
fontWeight: FontWeight.w600,
267264
),
268265
),
269266
const SizedBox(width: 8),
270-
Icon(currentStepData.isWelcome ? Icons.telegram : Icons.arrow_forward),
267+
Icon(
268+
currentStepData.isWelcome
269+
? Icons.telegram
270+
: Icons.arrow_forward,
271+
),
271272
],
272273
),
273274
),
@@ -320,15 +321,11 @@ class _OnboardingScreenState extends State<OnboardingScreen>
320321
color: step.color.withOpacity(0.1),
321322
shape: BoxShape.circle,
322323
),
323-
child: Icon(
324-
step.icon,
325-
size: 60,
326-
color: step.color,
327-
),
324+
child: Icon(step.icon, size: 60, color: step.color),
328325
),
329326
const SizedBox(height: 32),
330327
],
331-
328+
332329
// Title
333330
Text(
334331
step.title,
@@ -340,7 +337,7 @@ class _OnboardingScreenState extends State<OnboardingScreen>
340337
textAlign: TextAlign.center,
341338
),
342339
const SizedBox(height: 16),
343-
340+
344341
// Description
345342
Text(
346343
step.description,
@@ -351,7 +348,7 @@ class _OnboardingScreenState extends State<OnboardingScreen>
351348
),
352349
textAlign: TextAlign.center,
353350
),
354-
351+
355352
// Telegram bot handle
356353
if (step.telegramBot != null) ...[
357354
const SizedBox(height: 16),
@@ -399,4 +396,3 @@ class OnboardingStep {
399396
this.isLast = false,
400397
});
401398
}
402-

lib/services/config_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,3 @@ class ConfigService {
261261
print('===============================');
262262
}
263263
}
264-

lib/services/deep_link_service.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,29 @@ class DeepLinkService {
4848
}
4949

5050
// Обработка deep links во время работы приложения
51-
_subscription = _appLinks.uriLinkStream.listen((Uri? uri) {
52-
if (uri != null) {
53-
_handleDeepLink(uri.toString());
54-
}
55-
}, onError: (err) {
56-
print('❌ Deep link error: $err');
57-
});
51+
_subscription = _appLinks.uriLinkStream.listen(
52+
(Uri? uri) {
53+
if (uri != null) {
54+
_handleDeepLink(uri.toString());
55+
}
56+
},
57+
onError: (err) {
58+
print('❌ Deep link error: $err');
59+
},
60+
);
5861
}
5962

6063
/// Обработка deep link
6164
void _handleDeepLink(String link) {
6265
print('📎 Received deep link: $link');
63-
66+
6467
if (link.startsWith('vpnclient://')) {
6568
// Обработка deep link для завершения onboarding
6669
if (_onboardingService != null) {
6770
_onboardingService!.handleDeepLink(link);
6871
}
6972
}
70-
73+
7174
// Можно добавить обработку других deep links здесь
7275
// Например: vpnclient://add-server?url=...
7376
// или: vpnclient://connect?server_id=...
@@ -82,4 +85,3 @@ class DeepLinkService {
8285
print('DeepLinkService disposed');
8386
}
8487
}
85-

0 commit comments

Comments
 (0)