Mobiles_programming/lib/main.dart

37 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mobiles_labs_5th_semester/data/repositories/games_repository.dart';
import 'package:mobiles_labs_5th_semester/presentation/home_page/bloc/bloc.dart';
import 'presentation/home_page/home_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
home: RepositoryProvider<GamesRepository>(
//репозиторий будет создан только тогда, когда будет запрошен, а не сразу при создании виджета
lazy: true,
create: (_) => GamesRepository(),
child: BlocProvider(
//bloc будет создан сразу при создании виджета
lazy: false,
//context нужен, чтобы суметь обратиться к провайдеру, кот. выше по дереву
create: (context) => HomeBloc(context.read<GamesRepository>()),
child: const HomePage(title: 'Чернышев Георгий Янович'),
),
)
);
}
}