-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from PDG-NUTRI/155-chargement-durant-login-et…
…-register LoadingOverlay done
- Loading branch information
Showing
5 changed files
with
113 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class LoadingOverlay extends StatefulWidget { | ||
final Widget _child; | ||
final LoadingOverlayController _controller; | ||
LoadingOverlay( | ||
{required Widget child, LoadingOverlayController? controller, Key? key}) | ||
: _child = child, | ||
_controller = controller ?? LoadingOverlayController(), | ||
super( | ||
key: key, | ||
); | ||
|
||
@override | ||
State<LoadingOverlay> createState() => _LoadingOverlayState(); | ||
} | ||
|
||
class LoadingOverlayController extends ChangeNotifier { | ||
bool _isLoading = false; | ||
|
||
bool get isLoading => _isLoading; | ||
|
||
LoadingOverlayController(); | ||
|
||
void showLoadingOverlay() { | ||
_isLoading = true; | ||
notifyListeners(); | ||
} | ||
|
||
void hideLoadingOverlay() { | ||
_isLoading = false; | ||
notifyListeners(); | ||
} | ||
} | ||
|
||
class _LoadingOverlayState extends State<LoadingOverlay> { | ||
@override | ||
void initState() { | ||
widget._controller.addListener(() { | ||
setState(() {}); | ||
}); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Stack( | ||
children: [ | ||
widget._child, | ||
if (widget._controller.isLoading) | ||
Container( | ||
color: const Color.fromARGB(166, 0, 0, 0), | ||
child: Center( | ||
child: CircularProgressIndicator( | ||
color: Theme.of(context).colorScheme.primary, | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters