74 lines
1.9 KiB
Dart
74 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'app.dart';
|
|
import 'core/api.dart';
|
|
import 'core/config.dart';
|
|
import 'core/format.dart';
|
|
import 'core/http_api.dart';
|
|
import 'core/models.dart';
|
|
import 'core/providers.dart';
|
|
import 'core/theme.dart';
|
|
import 'widgets/ui.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final Api api = HttpApi(
|
|
baseUrl: AppConfig.apiBaseUrl,
|
|
prefs: await SharedPreferences.getInstance(),
|
|
);
|
|
runApp(_Boot(api));
|
|
}
|
|
|
|
class _Boot extends StatefulWidget {
|
|
const _Boot(this.api);
|
|
final Api api;
|
|
|
|
@override
|
|
State<_Boot> createState() => _BootState();
|
|
}
|
|
|
|
class _BootState extends State<_Boot> {
|
|
late final Future<AppUser?> _user = widget.api.restore().catchError(
|
|
(Object _) => null,
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) => FutureBuilder<AppUser?>(
|
|
future: _user,
|
|
builder: (context, snap) {
|
|
if (snap.connectionState != ConnectionState.done) {
|
|
return const _Splash();
|
|
}
|
|
return ProviderScope(
|
|
overrides: [
|
|
apiProvider.overrideWithValue(widget.api),
|
|
startDateProvider.overrideWithValue(dateOnly(widget.api.now)),
|
|
sessionProvider.overrideWith(() => SessionNotifier(snap.data)),
|
|
],
|
|
child: const SrsApp(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
class _Splash extends StatelessWidget {
|
|
const _Splash();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: DecoratedBox(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [C.navy, C.navyDeep],
|
|
),
|
|
),
|
|
child: const Center(child: BrandCoin(size: 96)),
|
|
),
|
|
);
|
|
}
|