banxiang/lib/main.dart.bak
2026-02-17 16:10:18 +08:00

85 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'theme.dart';
import 'services/auth_service.dart';
import 'screens/login_screen.dart';
import 'screens/main_screen.dart';
void main() {
runApp(const BanxiangApp());
}
class BanxiangApp extends StatelessWidget {
const BanxiangApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '伴享',
theme: AppTheme.lightTheme,
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('zh', 'CN')],
locale: const Locale('zh', 'CN'),
home: const SplashScreen(),
);
}
}
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_checkAuth();
}
void _checkAuth() async {
await Future.delayed(const Duration(seconds: 2));
final loggedIn = await AuthService.checkLoginStatus();
if (mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => loggedIn ? const MainScreen() : const LoginScreen()),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 100, height: 100,
decoration: BoxDecoration(
color: const Color(0xFF1976D2),
borderRadius: BorderRadius.circular(24),
),
child: const Icon(Icons.elderly, size: 56, color: Colors.white),
),
const SizedBox(height: 24),
const Text('伴享', style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold, color: Color(0xFF333333))),
const SizedBox(height: 8),
const Text('银发生活社交平台', style: TextStyle(fontSize: 16, color: Color(0xFF999999))),
const SizedBox(height: 48),
const SizedBox(width: 24, height: 24, child: CircularProgressIndicator(strokeWidth: 2)),
],
),
),
);
}
}