Files
ProxyTrash/lib/app.dart
2026-05-23 05:33:39 -06:00

107 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'models/auth_session.dart';
import 'screens/auth_screen.dart';
import 'screens/dashboard_screen.dart';
import 'services/address_repository.dart';
import 'services/auth_repository.dart';
class MyApp extends StatelessWidget {
const MyApp({
super.key,
AuthRepository? authRepository,
AddressRepository? addressRepository,
this.enableLiveFeatures = true,
}) : _authRepository = authRepository ?? const HttpAuthRepository(),
_addressRepository = addressRepository ?? const HttpAddressRepository();
final AuthRepository _authRepository;
final AddressRepository _addressRepository;
final bool enableLiveFeatures;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Acceso',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF0F766E)),
useMaterial3: true,
),
home: AuthBootstrap(
authRepository: _authRepository,
addressRepository: _addressRepository,
enableLiveFeatures: enableLiveFeatures,
),
);
}
}
class AuthBootstrap extends StatefulWidget {
const AuthBootstrap({
super.key,
required this.authRepository,
required this.addressRepository,
this.enableLiveFeatures = true,
});
final AuthRepository authRepository;
final AddressRepository addressRepository;
final bool enableLiveFeatures;
@override
State<AuthBootstrap> createState() => _AuthBootstrapState();
}
class _AuthBootstrapState extends State<AuthBootstrap> {
late final Future<AuthSession?> _sessionFuture;
@override
void initState() {
super.initState();
_sessionFuture = widget.authRepository.restoreSession();
}
@override
Widget build(BuildContext context) {
return FutureBuilder<AuthSession?>(
future: _sessionFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const _LoadingView();
}
final session = snapshot.data;
if (session != null) {
return DashboardScreen(
authRepository: widget.authRepository,
addressRepository: widget.addressRepository,
session: session,
savedAddress: null,
enableLiveFeatures: widget.enableLiveFeatures,
);
}
return AuthScreen(
authRepository: widget.authRepository,
addressRepository: widget.addressRepository,
enableLiveFeatures: widget.enableLiveFeatures,
);
},
);
}
}
class _LoadingView extends StatelessWidget {
const _LoadingView();
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
}