2024-12-16 22:27:12 +04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'data/repositories/hero_repository.dart';
|
|
|
|
import 'services/api_service.dart';
|
|
|
|
import 'presentation/home_page/bloc/hero_list_bloc.dart';
|
|
|
|
import 'components/screens/hero_list_screen.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'presentation/home_page/bloc/hero_search_bloc.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2024-12-16 23:50:05 +04:00
|
|
|
import '../../Components/locale/l10n/app_locale.dart';
|
|
|
|
|
2024-12-16 22:27:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
final apiService = ApiService(baseUrl: 'https://assets.deadlock-api.com');
|
|
|
|
final heroRepository = HeroRepository(apiService: apiService);
|
|
|
|
|
|
|
|
runApp(MyApp(heroRepository: heroRepository));
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
final HeroRepository heroRepository;
|
|
|
|
|
|
|
|
const MyApp({Key? key, required this.heroRepository}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Provider<HeroRepository>(
|
|
|
|
create: (_) => heroRepository,
|
|
|
|
child: BlocProvider(
|
|
|
|
create: (_) => HeroListBloc(heroRepository)..add(FetchHeroes()),
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) {
|
|
|
|
final heroListBloc = context.read<HeroListBloc>();
|
|
|
|
return BlocBuilder<HeroListBloc, HeroListState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is HeroListLoaded) {
|
|
|
|
return MultiBlocProvider(
|
|
|
|
providers: [
|
|
|
|
BlocProvider(
|
|
|
|
create: (_) => HeroSearchBloc(allHeroes: state.heroes),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: MaterialApp(
|
|
|
|
home: HeroListScreen(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return MaterialApp(
|
2024-12-16 23:50:05 +04:00
|
|
|
localizationsDelegates: AppLocale.localizationsDelegates,
|
|
|
|
supportedLocales: AppLocale.supportedLocales,
|
2024-12-16 22:27:12 +04:00
|
|
|
home: Scaffold(
|
|
|
|
body: Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|