OpenContacts/lib/main.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

2023-04-29 13:18:46 -04:00
import 'package:contacts_plus/widgets/home_screen.dart';
import 'package:contacts_plus/widgets/login_screen.dart';
import 'package:flutter/material.dart';
import 'api_client.dart';
import 'models/authentication_data.dart';
void main() {
2023-04-29 16:21:00 -04:00
runApp(ContactsPlus());
2023-04-29 13:18:46 -04:00
}
class ContactsPlus extends StatelessWidget {
2023-04-29 16:21:00 -04:00
ContactsPlus({super.key});
final Typography _typography = Typography.material2021(platform: TargetPlatform.android);
2023-04-29 13:18:46 -04:00
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Contacts+',
theme: ThemeData(
2023-04-29 16:21:00 -04:00
textTheme: _typography.white,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.purple, brightness: Brightness.dark)
2023-04-29 13:18:46 -04:00
),
home: const SplashScreen(),
);
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
2023-04-29 16:21:00 -04:00
final ApiClient _apiClient = ApiClient();
2023-04-29 13:18:46 -04:00
@override
Widget build(BuildContext context) {
2023-04-29 16:21:00 -04:00
if (_apiClient.isAuthenticated) {
return const HomeScreen();
2023-04-29 13:18:46 -04:00
} else {
return LoginScreen(
onLoginSuccessful: (AuthenticationData authData) {
if (authData.isAuthenticated) {
setState(() {
2023-04-29 16:21:00 -04:00
_apiClient.authenticationData = authData;
2023-04-29 13:18:46 -04:00
});
}
},
);
}
}
}