Use Telegram Login Widget for web auth
Some checks failed
Build and deploy Flutter Web / build (push) Has been cancelled

This commit is contained in:
Ruslan Bakiev
2026-05-08 18:27:03 +07:00
parent bccda6e9b6
commit be5c61a434
19 changed files with 186 additions and 91 deletions

View File

@@ -5,7 +5,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:latlong2/latlong.dart';
import '../auth/telegram_launcher.dart';
import '../auth/telegram_login_button.dart';
import '../models/place_models.dart';
import '../state/place_controller.dart';
@@ -14,10 +14,6 @@ const _mapboxStyle = String.fromEnvironment(
'MAPBOX_STYLE',
defaultValue: 'mapbox/streets-v12',
);
const _telegramBotUrl = String.fromEnvironment(
'TELEGRAM_BOT_URL',
defaultValue: 'https://t.me/carfteebot',
);
class MapflowShell extends ConsumerWidget {
const MapflowShell({super.key});
@@ -29,9 +25,8 @@ class MapflowShell extends ConsumerWidget {
return asyncState.when(
data: (state) => state.hasTelegramAuth
? _MapContent(state: state)
: _TelegramAuthGate(
onOpenTelegram: () => openTelegramUrl(_telegramBotUrl),
onRetry: () => ref.invalidate(placeControllerProvider),
: _TelegramLoginScreen(
onAuthenticated: () => ref.invalidate(placeControllerProvider),
),
loading: () => const _MapLoading(),
error: (error, _) => _MapError(message: error.toString()),
@@ -129,66 +124,34 @@ class _MapContent extends ConsumerWidget {
}
}
class _TelegramAuthGate extends StatelessWidget {
const _TelegramAuthGate({
required this.onOpenTelegram,
required this.onRetry,
});
class _TelegramLoginScreen extends StatelessWidget {
const _TelegramLoginScreen({required this.onAuthenticated});
final VoidCallback onOpenTelegram;
final VoidCallback onRetry;
final VoidCallback onAuthenticated;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
FlutterMap(
options: const MapOptions(
initialCenter: LatLng(10.7718, 106.6982),
initialZoom: 14.2,
),
children: [const _BaseMapTileLayer(), const _MapAttribution()],
),
ColoredBox(color: Colors.black.withValues(alpha: 0.18)),
SafeArea(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
margin: const EdgeInsets.all(12),
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFFFFFBF5),
borderRadius: BorderRadius.circular(8),
body: SafeArea(
child: Center(
child: SizedBox(
width: 320,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'MapFlow',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.w900,
letterSpacing: 0,
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Открой через Telegram, чтобы продолжить.',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w900,
letterSpacing: 0,
),
),
const SizedBox(height: 12),
FilledButton.icon(
onPressed: onOpenTelegram,
icon: const Icon(Icons.telegram),
label: const Text('Telegram'),
),
TextButton(
onPressed: onRetry,
child: const Text('Обновить'),
),
],
),
),
const SizedBox(height: 24),
TelegramLoginButton(onAuthenticated: onAuthenticated),
],
),
),
],
),
),
);
}