Skip to content

Commit e7b6035

Browse files
refactor: simplify sensor screens to use shared widget
- Convert GasSensorScreen and DustSensorScreen to StatelessWidget - Use FeatureNotImplementedScreen reusable component - Remove ~100 lines of duplicated code per file - Maintain same UX with cleaner implementation
1 parent 2897f00 commit e7b6035

2 files changed

Lines changed: 16 additions & 208 deletions

File tree

lib/view/dust_sensor_screen.dart

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,20 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter/services.dart';
32
import 'package:pslab/l10n/app_localizations.dart';
43
import 'package:pslab/providers/locator.dart';
5-
import 'package:pslab/view/widgets/common_scaffold_widget.dart';
4+
import 'package:pslab/view/widgets/feature_not_implemented_screen.dart';
65

7-
class DustSensorScreen extends StatefulWidget {
6+
class DustSensorScreen extends StatelessWidget {
87
const DustSensorScreen({super.key});
98

10-
@override
11-
State<DustSensorScreen> createState() => _DustSensorScreenState();
12-
}
13-
14-
class _DustSensorScreenState extends State<DustSensorScreen> {
15-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
16-
17-
@override
18-
void initState() {
19-
super.initState();
20-
_setPortraitOrientation();
21-
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
22-
}
23-
24-
@override
25-
void didChangeDependencies() {
26-
_setPortraitOrientation();
27-
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
28-
super.didChangeDependencies();
29-
}
30-
31-
void _setPortraitOrientation() {
32-
SystemChrome.setPreferredOrientations([
33-
DeviceOrientation.portraitUp,
34-
DeviceOrientation.portraitDown,
35-
]);
36-
}
37-
389
@override
3910
Widget build(BuildContext context) {
40-
return CommonScaffold(
11+
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
12+
13+
return FeatureNotImplementedScreen(
4114
title: appLocalizations.dustSensor,
42-
body: Center(
43-
child: Padding(
44-
padding: const EdgeInsets.all(24.0),
45-
child: Column(
46-
mainAxisAlignment: MainAxisAlignment.center,
47-
children: [
48-
Icon(
49-
Icons.blur_on,
50-
size: 120,
51-
color: Colors.grey.shade400,
52-
),
53-
const SizedBox(height: 32),
54-
Text(
55-
appLocalizations.dustSensor,
56-
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
57-
fontWeight: FontWeight.bold,
58-
color: Colors.black87,
59-
),
60-
),
61-
const SizedBox(height: 16),
62-
Text(
63-
appLocalizations.screenNotImplemented,
64-
textAlign: TextAlign.center,
65-
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
66-
color: Colors.grey.shade600,
67-
),
68-
),
69-
const SizedBox(height: 24),
70-
Container(
71-
padding: const EdgeInsets.all(16),
72-
decoration: BoxDecoration(
73-
color: Colors.orange.shade50,
74-
borderRadius: BorderRadius.circular(8),
75-
border: Border.all(color: Colors.orange.shade200),
76-
),
77-
child: Column(
78-
children: [
79-
Icon(
80-
Icons.info_outline,
81-
color: Colors.orange.shade700,
82-
size: 32,
83-
),
84-
const SizedBox(height: 8),
85-
Text(
86-
appLocalizations.dustSensorDesc,
87-
textAlign: TextAlign.center,
88-
style: TextStyle(
89-
color: Colors.orange.shade900,
90-
fontSize: 14,
91-
),
92-
),
93-
],
94-
),
95-
),
96-
const SizedBox(height: 32),
97-
ElevatedButton.icon(
98-
onPressed: () {
99-
Navigator.pop(context);
100-
},
101-
icon: const Icon(Icons.arrow_back),
102-
label: Text(appLocalizations.close),
103-
style: ElevatedButton.styleFrom(
104-
padding: const EdgeInsets.symmetric(
105-
horizontal: 24,
106-
vertical: 12,
107-
),
108-
),
109-
),
110-
],
111-
),
112-
),
113-
),
15+
description: appLocalizations.dustSensorDesc,
16+
icon: Icons.blur_on,
17+
accentColor: Colors.orange,
11418
);
11519
}
11620
}

lib/view/gas_sensor_screen.dart

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,20 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter/services.dart';
32
import 'package:pslab/l10n/app_localizations.dart';
43
import 'package:pslab/providers/locator.dart';
5-
import 'package:pslab/view/widgets/common_scaffold_widget.dart';
4+
import 'package:pslab/view/widgets/feature_not_implemented_screen.dart';
65

7-
class GasSensorScreen extends StatefulWidget {
6+
class GasSensorScreen extends StatelessWidget {
87
const GasSensorScreen({super.key});
98

10-
@override
11-
State<GasSensorScreen> createState() => _GasSensorScreenState();
12-
}
13-
14-
class _GasSensorScreenState extends State<GasSensorScreen> {
15-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
16-
17-
@override
18-
void initState() {
19-
super.initState();
20-
_setPortraitOrientation();
21-
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
22-
}
23-
24-
@override
25-
void didChangeDependencies() {
26-
_setPortraitOrientation();
27-
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
28-
super.didChangeDependencies();
29-
}
30-
31-
void _setPortraitOrientation() {
32-
SystemChrome.setPreferredOrientations([
33-
DeviceOrientation.portraitUp,
34-
DeviceOrientation.portraitDown,
35-
]);
36-
}
37-
389
@override
3910
Widget build(BuildContext context) {
40-
return CommonScaffold(
11+
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
12+
13+
return FeatureNotImplementedScreen(
4114
title: appLocalizations.gasSensor,
42-
body: Center(
43-
child: Padding(
44-
padding: const EdgeInsets.all(24.0),
45-
child: Column(
46-
mainAxisAlignment: MainAxisAlignment.center,
47-
children: [
48-
Icon(
49-
Icons.air,
50-
size: 120,
51-
color: Colors.grey.shade400,
52-
),
53-
const SizedBox(height: 32),
54-
Text(
55-
appLocalizations.gasSensor,
56-
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
57-
fontWeight: FontWeight.bold,
58-
color: Colors.black87,
59-
),
60-
),
61-
const SizedBox(height: 16),
62-
Text(
63-
appLocalizations.screenNotImplemented,
64-
textAlign: TextAlign.center,
65-
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
66-
color: Colors.grey.shade600,
67-
),
68-
),
69-
const SizedBox(height: 24),
70-
Container(
71-
padding: const EdgeInsets.all(16),
72-
decoration: BoxDecoration(
73-
color: Colors.blue.shade50,
74-
borderRadius: BorderRadius.circular(8),
75-
border: Border.all(color: Colors.blue.shade200),
76-
),
77-
child: Column(
78-
children: [
79-
Icon(
80-
Icons.info_outline,
81-
color: Colors.blue.shade700,
82-
size: 32,
83-
),
84-
const SizedBox(height: 8),
85-
Text(
86-
appLocalizations.gasSensorDesc,
87-
textAlign: TextAlign.center,
88-
style: TextStyle(
89-
color: Colors.blue.shade900,
90-
fontSize: 14,
91-
),
92-
),
93-
],
94-
),
95-
),
96-
const SizedBox(height: 32),
97-
ElevatedButton.icon(
98-
onPressed: () {
99-
Navigator.pop(context);
100-
},
101-
icon: const Icon(Icons.arrow_back),
102-
label: Text(appLocalizations.close),
103-
style: ElevatedButton.styleFrom(
104-
padding: const EdgeInsets.symmetric(
105-
horizontal: 24,
106-
vertical: 12,
107-
),
108-
),
109-
),
110-
],
111-
),
112-
),
113-
),
15+
description: appLocalizations.gasSensorDesc,
16+
icon: Icons.air,
17+
accentColor: Colors.blue,
11418
);
11519
}
11620
}

0 commit comments

Comments
 (0)