Created
July 30, 2018 20:08
-
-
Save mikeevstropov/52cfd9f0265db3b8ed15c0d0528fa751 to your computer and use it in GitHub Desktop.
reactivity issue
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
import 'package:flutter/material.dart'; | |
enum NotifiedContainerType { | |
success, | |
info, | |
warning, | |
error | |
} | |
class NotifiedContainer extends StatefulWidget { | |
final bool noticeDisplayed; | |
final NotifiedContainerType type; | |
final String message; | |
final Widget child; | |
NotifiedContainer({ | |
this.noticeDisplayed = true, | |
this.type = NotifiedContainerType.info, | |
this.message = 'Empty message', | |
this.child | |
}) : super(); | |
@override | |
State<StatefulWidget> createState() => _NotifiedContainerState( | |
noticeDisplayed: noticeDisplayed, | |
type: type, | |
message: message, | |
child: child | |
); | |
} | |
class _NotifiedContainerState extends State<NotifiedContainer> { | |
bool noticeDisplayed; | |
NotifiedContainerType type; | |
String message; | |
Widget child; | |
_NotifiedContainerState({ | |
this.noticeDisplayed, | |
this.type, | |
this.message, | |
this.child | |
}) : super(); | |
@override | |
Widget build(BuildContext context) { | |
if (!this.noticeDisplayed) | |
return child; | |
Color color; | |
switch (type) { | |
case NotifiedContainerType.success: | |
color = Color(0xFF36C8A0); | |
break; | |
case NotifiedContainerType.info: | |
color = Color(0xFFBBBBBB); | |
break; | |
case NotifiedContainerType.warning: | |
color = Color(0xFFFFE900); | |
break; | |
case NotifiedContainerType.error: | |
color = Color(0xFFF43551); | |
break; | |
default: | |
throw 'Unknown value of NotifiedContainerType.'; | |
} | |
Widget notification = Container( | |
padding: EdgeInsets.fromLTRB( | |
20.0, | |
40.0, | |
20.0, | |
20.0 | |
), | |
width: double.infinity, | |
color: color, | |
child: Text( | |
message, | |
style: TextStyle( | |
fontSize: 16.0, | |
color: Color(0xFFFFFFFF) | |
), | |
), | |
); | |
return Stack( | |
children: <Widget>[ | |
child, | |
notification | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment