proxibuy/lib/main.dart

167 lines
6.0 KiB
Dart

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:proxibuy/data/models/datasources/offer_data_source.dart';
import 'package:proxibuy/data/repositories/offer_repository.dart';
import 'package:proxibuy/firebase_options.dart';
import 'package:proxibuy/presentation/auth/bloc/auth_bloc.dart';
import 'package:proxibuy/presentation/notification_preferences/bloc/notification_preferences_bloc.dart';
import 'package:proxibuy/presentation/offer/bloc/offer_bloc.dart';
import 'package:proxibuy/presentation/pages/offers_page.dart';
import 'package:proxibuy/presentation/pages/otp_page.dart';
import 'package:proxibuy/presentation/pages/user_info_page.dart';
import 'package:proxibuy/presentation/reservation/cubit/reservation_cubit.dart';
// import 'package:proxibuy/services/mqtt_service.dart';
import 'core/config/app_colors.dart';
import 'presentation/pages/onboarding_page.dart';
import 'package:proxibuy/presentation/pages/splash_screen.dart'; // <--- ایمپورت جدید
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
Animate.restartOnHotReload = true;
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<AuthBloc>(
create: (context) => AuthBloc()..add(CheckAuthStatusEvent()),
),
RepositoryProvider<OfferRepository>(
create: (context) =>
OfferRepository(offerDataSource: MockOfferDataSource()),
),
BlocProvider<ReservationCubit>(
create: (context) => ReservationCubit(),
),
BlocProvider<OffersBloc>(
create: (context) => OffersBloc(
offerRepository: context.read<OfferRepository>(),
),
),
BlocProvider<NotificationPreferencesBloc>(
create: (context) => NotificationPreferencesBloc(),
),
],
child: MaterialApp(
title: 'Proxibuy',
debugShowCheckedModeBanner: false,
home: const SplashScreen(), // <--- استفاده از صفحه اسپلش
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('fa')],
locale: const Locale('fa'),
theme: ThemeData(
fontFamily: 'Dana',
scaffoldBackgroundColor: Colors.white,
colorScheme: ColorScheme.fromSeed(
seedColor: AppColors.primary,
primary: AppColors.primary,
surface: Colors.white,
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: Colors.white,
floatingLabelBehavior: FloatingLabelBehavior.always,
contentPadding: const EdgeInsets.symmetric(
vertical: 18,
horizontal: 20,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: AppColors.border),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: AppColors.border),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: AppColors.primary, width: 2),
),
labelStyle: const TextStyle(color: Colors.black),
// ignore: deprecated_member_use
hintStyle: TextStyle(color: Colors.black.withOpacity(0.8)),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: Colors.black,
padding: const EdgeInsets.symmetric(vertical: 16),
side: const BorderSide(color: Colors.grey),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
textStyle: const TextStyle(
fontFamily: 'Dana',
fontSize: 16,
color: Colors.black,
),
),
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.button,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
textStyle: const TextStyle(
fontFamily: 'Dana',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
}
}
class AppRouter extends StatelessWidget {
const AppRouter({super.key});
@override
Widget build(BuildContext context) {
final authState = context.select((AuthBloc bloc) => bloc.state);
if (authState is AuthCodeSentSuccess) {
return OtpPage(
phoneNumber: "+${authState.countryCode}${authState.phone}",
phone: authState.phone,
countryCode: authState.countryCode,
);
}
if (authState is AuthLoading) {
final currentState = context.read<AuthBloc>().state;
if (currentState is! AuthCodeSentSuccess) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
}
if (authState is AuthSuccess) {
return const OffersPage();
}
if (authState is AuthNeedsInfo) {
return const UserInfoPage();
}
return const OnboardingPage();
}
}