build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
context
using BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
int referenceWidth = 720;
int referenceHeight = 1440;
// Using MediaQuery to get the screen size of the current device
Size screenSize = MediaQuery.of(context).size;
double screenWidth = screenSize.width;
double screenHeight = screenSize.height;
// Calculate the scale factors
double scaleWidth = screenWidth / referenceWidth;
double scaleHeight = screenHeight / referenceHeight;
MediaQueryData mediaQueryData = MediaQuery.of(context);
return Scaffold(
// bottomNavigationBar: BottomNavBarBackToHome(
// isDeclared: isDeclared,
// isLandingPage: true,
// isSubmitted: submitted,
// onTap: quizStatus == 'active'
// ? onStartQuiz
// : () {
// log("Navigating to home", name: 'RulesScreen');
// Navigator.of(context).pop();
// Navigator.of(context).pop();
// },
// quizStatus: quizStatus,
// ),
extendBodyBehindAppBar: true,
appBar: AppBar(
actions: [],
backgroundColor: Colors.transparent,
elevation: 0,
systemOverlayStyle: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
),
leading: IconButton(
icon: const Icon(
Icons.close,
color: Color(0xff495E10),
),
onPressed: () {
NudgeGlobalCallback().triggerCallback("QuizClose", "QuizClosed");
Navigator.of(context).pop();
Navigator.of(context).pop();
},
),
),
backgroundColor: const Color(0xffA6CE3A),
body: WillPopScope(
onWillPop: ()async {
// Nlo
NudgeGlobalCallback().triggerCallback("QuizClose", "QuizClosed");
NudgeGlobalCallback().triggerCallback("NUDGE_QUIZ", QuizEvent.DISMISSED.value);
Navigator.of(context).pop();
Navigator.of(context).pop();
return false;
},
child: SingleChildScrollView(
// Makes the whole body scrollable
child: Stack(
children: [
CachedNetworkImage(
height: MediaQuery.of(context).size.height,
width: double.infinity,
fit: BoxFit.cover, imageUrl: bgUrl!,
),
SizedBox(
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(
height: kToolbarHeight * 1.35,
),
const Spacer(),
const SizedBox(height: 20),
if (quizStatus == 'active')
Center(
child: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xffA6CE3A),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(0),
bottomRight: Radius.circular(0),
),
border: Border.all(
color: const Color(0xff728F24),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 30,
vertical: 0,
),
child: Text(
"$heading :",
style: const TextStyle(
fontFamily: 'Inter',
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
),
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 40,
vertical: 10,
),
child: SizedBox(
width: double.infinity,
child: quizStatus == 'active' || submitted
? Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
...rules.text.map(
(rule) => Padding(
padding: const EdgeInsets.only(
bottom: 10,
),
child: Row(
mainAxisAlignment: () {
if (rules.alignment == 'center') {
return MainAxisAlignment.center;
} else if (rules.alignment == 'left') {
return MainAxisAlignment.start;
} else if (rules.alignment == 'right') {
return MainAxisAlignment.end;
} else {
return MainAxisAlignment.center;
}
}(),
children: [
// Container(
// margin: const EdgeInsets.only(right: 10),
// height: 5,
// width: 5,
// decoration: const BoxDecoration(
// color: Colors.black,
// shape: BoxShape.circle,
// ),
// ),
Expanded(
child: Text(
textAlign: () {
if (rules.alignment == 'center') {
return TextAlign.center;
} else if (rules.alignment ==
'left') {
return TextAlign.left;
} else if (rules.alignment ==
'right') {
return TextAlign.right;
} else {
return TextAlign.center;
}
}(),
rule,
overflow: TextOverflow.visible,
softWrap: true,
maxLines: 3,
style: TextStyle(
// height: rules.lineHeight /
// (7 * mediaQueryData.devicePixelRatio),
fontFamily: 'Inter',
fontWeight:
FontWeight.values.firstWhere(
(e) =>
e.toString() ==
'FontWeight.w${rules.fontWeight}',
),
color: Color(
int.parse(
rules.fontColor
.substring(1),
radix: 16,
) +
0xFF000000,
),
fontSize:
rules.fontSize.toDouble() *
scaleHeight,
),
),
),
],
),
),
),
],
)
: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: const BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
height: 5,
width: 5,
),
const Text(
" The quiz is not live right now.",
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: const BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
height: 5,
width: 5,
),
const Text(
" Please come back at 6 AM to participate.",
),
],
),
const SizedBox(
height: 20,
),
],
),
),
),
const SizedBox(height: 20),
// const Spacer(),
BottomNavContainer(
isDeclared: false,
isLandingPage: true,
isSubmitted: submitted,
onTap: quizStatus == 'active'
? onStartQuiz
: submitted
? onStartQuiz
: () {
log("Navigating to home", name: 'RulesScreen');
Navigator.of(context).pop();
Navigator.of(context).pop();
},
quizStatus: quizStatus,
)
],
),
),
],
),
),
),
);
}