Skip to content

Commit ad27ef0

Browse files
committed
Migliorato codice
Migliorata una condizione if Eliminata variabile ormai inutile Cambiate variabili pubbliche in private
1 parent 1b260fd commit ad27ef0

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

KeepReading/lib/page/home_page.dart

+8-15
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class HomePage extends StatefulWidget {
1818
}
1919

2020
class _HomePageState extends State<HomePage> {
21-
bool fileExists = false;
22-
String filePath = "";
21+
String _filePath = "";
2322

2423
// at start is a CircularProgressIndicator then check if file exists
2524
// and it can be a PDFViewerPage or NoFilePage
@@ -38,14 +37,13 @@ class _HomePageState extends State<HomePage> {
3837
// */
3938
void setStateFile(String path) {
4039
setState(() {
41-
fileExists = true;
42-
filePath = path;
40+
_filePath = path;
4341

4442
_body = PDFViewer(
4543
appName: appName,
4644
deleteFile: deleteFile,
47-
filePath: filePath,
48-
updateCallback: _checkUpdate,
45+
filePath: _filePath,
46+
updateCallback: _checkUpdateOnStart,
4947
);
5048
});
5149
}
@@ -57,14 +55,13 @@ class _HomePageState extends State<HomePage> {
5755
// */
5856
void setStateNoFile() {
5957
setState(() {
60-
fileExists = false;
61-
filePath = "";
58+
_filePath = "";
6259

6360
_body = NoFilePage(
6461
appName: appName,
6562
notifyParent: fileLoaded,
6663
deleteFile: deleteFile,
67-
updateCallback: _checkUpdate,
64+
updateCallback: _checkUpdateOnStart,
6865
);
6966
});
7067
}
@@ -103,19 +100,15 @@ class _HomePageState extends State<HomePage> {
103100
void isFileSaved() async {
104101
final bool result = await FileManager.existsManual();
105102

106-
if (result) {
107-
fileLoaded();
108-
} else {
109-
setStateNoFile();
110-
}
103+
(result) ? fileLoaded() : setStateNoFile();
111104
}
112105

113106
//**
114107
// * Check if the app has an update
115108
// * only on the first time the app is opened
116109
// * void
117110
// */
118-
void _checkUpdate() async {
111+
void _checkUpdateOnStart() async {
119112
if (!UpdateManager.reCheckingUpdate &&
120113
await UpdateManager.isUpdateAvailable()) {
121114
UpdateManager.showNewUpdateMessage(context);

KeepReading/lib/page/pdfviewer_page.dart

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class PDFViewer extends StatefulWidget {
2525

2626
class _PDFViewerState extends State<PDFViewer> {
2727
late PageController _controller;
28-
List<Image> pages = [];
29-
bool loaded = false;
28+
List<Image> _pages = [];
29+
bool _loaded = false;
3030

3131
@override
3232
void initState() {
@@ -37,7 +37,7 @@ class _PDFViewerState extends State<PDFViewer> {
3737

3838
@override
3939
void dispose() {
40-
pages.clear();
40+
_pages.clear();
4141
_controller.dispose();
4242
super.dispose();
4343
}
@@ -48,8 +48,8 @@ class _PDFViewerState extends State<PDFViewer> {
4848
// */
4949
void updatePages(List<Image> pages) async {
5050
setState(() {
51-
this.pages = pages;
52-
loaded = true;
51+
_pages = pages;
52+
_loaded = true;
5353
});
5454

5555
// perform the update check after setState is executed
@@ -76,20 +76,20 @@ class _PDFViewerState extends State<PDFViewer> {
7676
appBar: MyAppBar(
7777
appName: widget.appName,
7878
deleteFile: widget.deleteFile,
79-
showMenuButton: loaded,
80-
deleteEnabled: loaded,
81-
updateEnabled: loaded,
79+
showMenuButton: _loaded,
80+
deleteEnabled: _loaded,
81+
updateEnabled: _loaded,
8282
),
8383
body: Center(
84-
child: (loaded)
84+
child: (_loaded)
8585
? PDFGallery(
8686
controller: _controller,
87-
pages: pages,
87+
pages: _pages,
8888
)
8989
: const CircularProgressIndicator(),
9090
),
9191
bottomNavigationBar:
92-
(loaded) ? MyBottomNavigationBar(jumpToPage: _jumpToPage) : null,
92+
(_loaded) ? MyBottomNavigationBar(jumpToPage: _jumpToPage) : null,
9393
);
9494
}
9595
}

0 commit comments

Comments
 (0)