build method
- BuildContext context
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
contextusing 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) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (isInit.isFalse) {
isInit.value = true;
if (controller.userProfileModel.value.data == null) {
if (currentRoute() != Routes.PROFILE) {
controller.getUserProfile();
notificationsController.getNotifications(showLoading: false);
}
}
}
});
return LayoutBuilder(builder: (context, constraints) {
final isPhone = context.x <= 960;
final current = ModalRoute.of(context)?.settings.name;
final list = <Widget>[
_menuButton(
title: 'Welcome',
isCurrent: current == Routes.HOME,
onClick: () {
goto(Routes.HOME);
},
),
_menuButton(
title: 'Travel',
isCurrent: current == Routes.TOP_FLIGHTS,
onClick: () {
goto(Routes.TOP_FLIGHTS);
},
),
_menuButton(
title: 'Search-Credits',
isCurrent: current == Routes.SEARCH_CREDIT,
onClick: () {
goto(Routes.SEARCH_CREDIT);
},
),
_menuButton(
title: 'Memberships',
isCurrent: current == Routes.SUBSCRIPTION,
onClick: () {
goto(Routes.SUBSCRIPTION);
},
),
// if (context.x > 1100 || context.x <= 960)
// _menuButton(
// title: 'ASmallWorld',
// isCurrent: current == Routes.A_SMALL_WORLD,
// onClick: () {
// goto(Routes.A_SMALL_WORLD);
// },
// ),
if (context.x >= 1100 || context.x <= 960)
_menuButton(
title: 'The Club',
isCurrent: current == Routes.THE_CLUB,
onClick: () {
goto(Routes.THE_CLUB);
},
),
// if (context.x > 1400 || context.x <= 960)
// _menuButton(
// title: 'Loyalty Rewards',
// isCurrent: current == Routes.LOYALTY_NEO_MILES,
// onClick: () {
// goto(Routes.LOYALTY_NEO_MILES);
// },
// ),
if (context.x > 960)
_menuButton(
title: 'More',
svgPath: 'assets/home/ic_down.svg',
isCurrent: false,
key: moreKey,
onClick: () {
_moreMenu(moreKey, context);
},
),
];
Widget myDivider() => Container(
height: 0.5.dp,
color: ColorHelper.bGBlueTint,
);
if (isPhone) {
// return Container(
// color: topSpace == false ? Colors.transparent : ColorHelper.white,
// alignment: Alignment.center,
// child: SingleChildScrollView(
// child: ExpansionTile(
// dense: false,
// initiallyExpanded: false,
// childrenPadding: EdgeInsets.zero,
// tilePadding: EdgeInsets.zero,
// trailing: Padding(
// padding: EdgeInsets.only(right: 24.dp),
// child: Row(
// mainAxisSize: MainAxisSize.min,
// children: [
// IconButton(
// onPressed: onNotificationClicked ??
// () {
// Scaffold.of(context).openEndDrawer();
// },
// icon: SvgPicture.asset(
// 'assets/home/notification.svg',
// width: 20.dp,
// height: 23.dp,
// ),
// ),
// 21.dp.SpaceY,
// _neoPassMenu(),
// 21.dp.SpaceY,
// SvgPicture.asset(
// 'assets/home/ic_menu.svg',
// width: 22.dp,
// height: 16.dp,
// ),
// ],
// ),
// ),
// shape: Border.symmetric(
// horizontal: BorderSide(
// width: 0.5.dp,
// color: ColorHelper.neutralDark,
// ),
// ),
// leading: Padding(
// padding: EdgeInsets.only(left: 24.dp),
// child: InkWell(
// onTap: () {
// goto(Routes.HOME);
// },
// child: Image.asset(
// 'assets/neopass-logo-light-flat-2-curved.png',
// height: 30,
// ),
// ),
// ),
// title: SizedBox(
// height: 45.dp,
// ),
// children: [
// for (var i = 0; i < list.length; i++) ...[
// if (i != 0)
// Container(
// height: 0.5.dp,
// color: ColorHelper.bGBlueTint,
// ),
// Padding(
// padding:
// EdgeInsets.symmetric(vertical: 2.dp, horizontal: 12),
// child: list[i],
// ),
// ],
// Container(
// height: 0.5.dp,
// color: ColorHelper.bGBlueTint,
// ),
// InkWell(
// key: key,
// onTap: () {
// isMoreOpen.value = !isMoreOpen.value;
// },
// child: Container(
// padding: EdgeInsets.symmetric(
// vertical: 20.dp, horizontal: 24.dp),
// child: Row(
// children: [
// Text(
// 'More',
// style: TextStyle(
// fontSize: 16.dp,
// fontWeight: FontWeight.w400,
// color: ColorHelper.neutralDark,
// ),
// ),
// const Spacer(),
// SvgPicture.asset(
// 'assets/home/ic_down.svg',
// width: 16.dp,
// height: 16.dp,
// ),
// ],
// ),
// ),
// ),
// Obx(() {
// return Visibility(
// visible: isMoreOpen.value,
// child: Column(
// children: [
// _expandedMenuButton(
// 'A Small World',
// () {
// goto(Routes.A_SMALL_WORLD);
// },
// ),
// _expandedMenuButton(
// 'Leon Security',
// () {},
// ),
// _expandedMenuButton(
// 'Travel & Entertainment',
// () {
// goto(Routes.TRAVEL);
// },
// ),
// _expandedMenuButton(
// 'Loyalty Rewards',
// () {
// goto(Routes.LOYALTY_NEO_MILES);
// },
// ),
// if (controller.userProfileModel.value.data?.isFounder ??
// false)
// _expandedMenuButton(
// 'Founders',
// () {
// goto(Routes.FOUNDERS);
// },
// ),
// _expandedMenuButton('Share your Benefits', () async {
// Requests.box.write('share_your_benefits', true);
// await Requests.box.save();
// await offAllUntil(Routes.LOYALTY_NEO_MILES,
// ModalRoute.withName('/home'));
// }),
// _expandedMenuButton(
// 'Contact Us',
// () {
// goto(Routes.CONTACTUS);
// },
// ),
// ],
// ),
// );
// }),
// 10.SpaceX,
// Container(
// height: 0.5.dp,
// color: ColorHelper.bGBlueTint,
// ),
// ],
// ),
// ),
// );
//Adding items to list
// list.add(_menuButton(
// title: 'Loyalty NEO-Miles',
// isCurrent: current == Routes.LOYALTY_NEO_MILES,
// onClick: () {
// goto(Routes.LOYALTY_NEO_MILES);
// },
// ));
// list.add(_menuButton(
// title: 'Share your Benefits',
// isCurrent: current == Routes.GLOBAL_IMPACT,
// onClick: () async {
// goto(Routes.GLOBAL_IMPACT);
// },
// ));
// list.add(_menuButton(
// title: 'Seamless Payments',
// isCurrent: current == Routes.NEO_ONE_PAYMENT,
// onClick: () async {
// goto(Routes.NEO_ONE_PAYMENT);
// },
// ));
// list.add(_menuButton(
// title: 'Navigator',
// isCurrent: current == Routes.AI_NAVIGATOR,
// onClick: () async {
// goto(Routes.AI_NAVIGATOR);
// },
// ));
// list.add(_menuButton(
// title: 'FAQ',
// isCurrent: current == Routes.FAQ,
// onClick: () {
// goto(Routes.FAQ);
// },
// ));
// list.add(_menuButton(
// title: 'Contact Us',
// isCurrent: current == Routes.FAQ,
// onClick: () {
// goto(Routes.FAQ);
// },
// ));
return Container(
color: topSpace == false ? Colors.transparent : ColorHelper.white,
alignment: Alignment.center,
child: SingleChildScrollView(
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: Padding(
padding: EdgeInsets.only(left: 24.dp),
child: InkWell(
onTap: () {
goto(Routes.HOME);
},
child: Image.asset(
'assets/neopass-logo-light-flat-2-curved.png',
height: 30,
),
),
),
title: SizedBox(height: 45.dp),
trailing: Padding(
padding: EdgeInsets.only(right: 24.dp),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Builder(
builder: (context) {
return Stack(
children: [
IconButton(
onPressed: onNotificationClicked ??
() {
Scaffold.of(context).openEndDrawer();
notificationsController.getNotifications();
},
icon: SvgPicture.asset(
'assets/home/notification.svg',
width: 20.dp,
height: 23.dp,
),
),
Positioned(
right: 4,
top: 0,
child: Obx(() {
int notificationCount = notificationsController.unreadNotifications.value;
return notificationCount > 0
? InkWell(
onTap: onNotificationClicked ??
() {
Scaffold.of(context).openEndDrawer();
},
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Text(
notificationCount.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
),
)
: const SizedBox();
}),
),
],
);
},
),
12.SpaceY,
_neoPassMenu(),
21.dp.SpaceY,
InkWell(
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
isDismissible: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
backgroundColor: Colors.white,
builder: (context) {
return SizedBox(
height: MediaQuery.of(context).size.height,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20.dp, horizontal: 12.dp),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.dp, vertical: 8.dp),
child: Row(
children: [
InkWell(
onTap: () {
goto(Routes.HOME);
},
child: Image.asset(
'assets/neopass-logo-light-flat-2-curved.png',
height: 30,
),
),
const Spacer(),
Builder(
builder: (context) {
return Stack(
children: [
IconButton(
onPressed: onNotificationClicked,
icon: SvgPicture.asset(
'assets/home/notification.svg',
width: 20.dp,
height: 23.dp,
),
),
Positioned(
right: 4,
top: 0,
child: Obx(() {
int notificationCount = notificationsController.unreadNotifications.value;
return notificationCount > 0
? InkWell(
onTap: onNotificationClicked,
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Text(
notificationCount.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
),
)
: const SizedBox();
}),
),
],
);
},
),
5.SpaceY,
_neoPassMenu(),
5.SpaceY,
IconButton(
icon: Icon(
Icons.close,
size: 24.dp,
color: Colors.black,
),
onPressed: () {
Navigator.pop(context);
},
),
],
),
),
Expanded(
child: ListView(
controller: miniScrollController,
children: [
for (var i = 0; i < list.length; i++) ...[
if (i != 0) myDivider(),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 20),
child: list[i],
),
myDivider(),
],
Padding(
padding: const EdgeInsets.symmetric(vertical: 15),
child: InkWell(
key: more2Key,
onTap: (){
isPhoneMoreOpen.value = !isPhoneMoreOpen.value;
if (isPhoneMoreOpen.value) {
// Scroll to the last item after a slight delay
Future.delayed(const Duration(milliseconds: 300), () {
miniScrollController.animateTo(
miniScrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut,
);
});
}
},
child: Obx(
()=>Container(
padding: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 12.dp),
child: Row(
children: [
Text(
'More',
style: TextStyle(
fontSize: 16.dp,
fontWeight: FontWeight.w400,
color: ColorHelper.neutralDark,
),
),
const Spacer(),
(!isPhoneMoreOpen.value)? SvgPicture.asset(
'assets/home/ic_down.svg',
width: 16.dp,
height: 16.dp,
):Transform.rotate(
angle: 180 * (3.1415926535897932 / 180), // Convert degrees to radians
child: SvgPicture.asset(
'assets/home/ic_down.svg',
width: 16.dp,
height: 16.dp,
)
)
],
),
)
),
),
),
6.dp.SpaceX,
isPhoneMoreMenuItem(context, 'Deep-Search Request', Routes.DEEP_SEARCH),
// isPhoneMoreMenuItem(context, 'Loyalty NEO-Miles', Routes.LOYALTY_NEO_MILES),
isPhoneMoreMenuItem(context, 'Share Your Benefits', Routes.GLOBAL_IMPACT),
isPhoneMoreMenuItem(context, 'Seamless Payments', Routes.NEO_ONE_PAYMENT),
isPhoneMoreMenuItem(context, 'Navigator', Routes.AI_NAVIGATOR),
isPhoneMoreMenuItem(context, 'FAQ', 'faq'),
isPhoneMoreMenuItem(context, 'Your Feedback', Routes.FEEDBACK_FORM),
isPhoneMoreMenuItem(context, 'Contact Us', 'Contact'),
])),
],
),
),
);
},
);
},
child: SvgPicture.asset(
'assets/home/ic_menu.svg',
width: 22.dp,
height: 16.dp,
),
),
],
),
),
),
),
);
}
return Column(
children: [
Container(
constraints: const BoxConstraints(maxWidth: 1100),
height: 60.dp,
color: topSpace == false ? Colors.transparent : ColorHelper.white,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// 73.dp.SpaceY,
InkWell(
onTap: () {
goto(Routes.HOME);
},
child: Image.asset(
'assets/neopass-logo-light-flat-2-curved.png',
width: 178,
height: 38,
),
),
50.SpaceY,
for (var i = 0; i < list.length; i++) ...[
if (i != 0)
const Expanded(
flex: 1,
child: SizedBox(),
),
list[i],
],
const Expanded(
flex: 7,
child: SizedBox(),
),
Builder(
builder: (context) {
return Stack(
children: [
IconButton(
onPressed: onNotificationClicked ??
() {
Scaffold.of(context).openEndDrawer();
notificationsController.getNotifications();
},
icon: SvgPicture.asset(
'assets/home/notification.svg',
width: 20.dp,
height: 23.dp,
),
),
Positioned(
right: 4,
top: 0,
child: Obx(() {
int notificationCount = notificationsController.unreadNotifications.value;
return notificationCount > 0
? InkWell(
onTap: onNotificationClicked ??
() {
Scaffold.of(context).openEndDrawer();
},
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Text(
notificationCount.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
),
)
: const SizedBox();
}),
),
],
);
},
),
12.SpaceY,
_neoPassMenu(),
// 73.dp.SpaceY,
],
),
),
if (bottomDivider)
Container(
height: 0.5,
width: double.infinity,
color: ColorHelper.genericBorderColor,
),
],
);
});
}