Skip to content

Commit c911341

Browse files
committed
Optimize Monument3DModelBloc loading with lazy initialization and convert to StatelessWidget
1 parent 57a4d1a commit c911341

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

lib/presentation/popular_monuments/mobile/popular_monuments_view_mobile.dart

+29-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
23
import 'package:monumento/application/popular_monuments/monument_3d_model/monument_3d_model_bloc.dart';
34
import 'package:monumento/presentation/popular_monuments/mobile/widgets/popular_monument_view_mobile_app_bar.dart';
45
import 'package:monumento/presentation/popular_monuments/mobile/widgets/populat_monuments_view_body_mobile.dart';
@@ -7,42 +8,39 @@ import 'package:monumento/service_locator.dart';
78
import 'package:monumento/utils/app_colors.dart';
89
import 'package:monumento/utils/app_text_styles.dart';
910

10-
class PopularMonumentsViewMobile extends StatefulWidget {
11+
class PopularMonumentsViewMobile extends StatelessWidget {
1112
const PopularMonumentsViewMobile({super.key});
1213

13-
@override
14-
State<PopularMonumentsViewMobile> createState() =>
15-
_PopularMonumentsViewMobileState();
16-
}
17-
18-
class _PopularMonumentsViewMobileState
19-
extends State<PopularMonumentsViewMobile> {
20-
@override
21-
void initState() {
22-
locator<Monument3dModelBloc>().add(const ViewMonument3DModel(
23-
monumentName: "Mount Rushmore National Memorial"));
24-
super.initState();
25-
}
26-
2714
@override
2815
Widget build(BuildContext context) {
29-
return Scaffold(
30-
appBar: PopularMonumnetsViewMobileAppBar(),
31-
body: PopularMonumentsViewMobileBodyBlocBuilder(),
32-
floatingActionButton: FloatingActionButton.extended(
33-
onPressed: () async {
34-
await Navigator.push(context,
35-
MaterialPageRoute(builder: (_) => const ScanMonumentsScreen()));
36-
},
37-
label: Text(
38-
"Scan Monuments",
39-
style: AppTextStyles.textStyle(
40-
fontType: FontType.MEDIUM, size: 14, isBody: true),
16+
return BlocProvider<Monument3dModelBloc>(
17+
create: (context) => locator<Monument3dModelBloc>()
18+
..add(
19+
const ViewMonument3DModel(
20+
monumentName: "Mount Rushmore National Memorial",
21+
),
22+
),
23+
lazy:
24+
true, //* Default is true; initializes the object only when it's needed.
25+
26+
child: Scaffold(
27+
appBar: PopularMonumnetsViewMobileAppBar(),
28+
body: PopularMonumentsViewMobileBodyBlocBuilder(),
29+
floatingActionButton: FloatingActionButton.extended(
30+
onPressed: () async {
31+
await Navigator.push(context,
32+
MaterialPageRoute(builder: (_) => const ScanMonumentsScreen()));
33+
},
34+
label: Text(
35+
"Scan Monuments",
36+
style: AppTextStyles.textStyle(
37+
fontType: FontType.MEDIUM, size: 14, isBody: true),
38+
),
39+
backgroundColor: AppColor.appPrimary,
40+
extendedPadding:
41+
const EdgeInsets.symmetric(vertical: 10, horizontal: 18),
42+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
4143
),
42-
backgroundColor: AppColor.appPrimary,
43-
extendedPadding:
44-
const EdgeInsets.symmetric(vertical: 10, horizontal: 18),
45-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
4644
),
4745
);
4846
}

0 commit comments

Comments
 (0)