Open ehcpdeveloper opened 1 year ago
Getting the Same issue, Tried below work around, I kept that code in side a Future Delayed.
Future.delayed(Duration.zero,() {
// put your logic using Get.width
},);
Tested with newer version flutter 3.13.4, same situation.
Experiencing the same issue. Anyone had any luck?
This error occurs because:
Get.width
outside the build method of a widget. Get.width
before it's available due to widget lifecycle considerations. In such cases, you should use it after the widget has been built, for example, in the initState
method or a callback triggered by a layout event.
`import 'package:flutter/material.dart'; import 'package:get/get.dart';
class MyWidget extends StatelessWidget { @override Widget build(BuildContext context) { // You can safely use Get.width within the build method double screenWidth = Get.width;
return Container(
width: screenWidth,
height: 100,
color: Colors.blue, );}}
I am using Get.width inside build method still getting the same error
return Image.network( widget.banners[index].getThumbnail(), fit: BoxFit.cover, height: 428, width: Get.width, // width: MediaQuery.of(context).size.width, );
From the docs:
Get.widget should not be used inside widgets or build methods. Use context.width instead of.
Get.widget should be used after build cycles (like in a button's onPressed) and input user actions.
Why? Because during the construction of the widget it is not available (or outdated), but later (when user input events are available) it has the updated value and is ready to use. If you are inside the widget tree, you have easy access to context, then context.widget will be the best option.
any solution?
Describe the bug Get.width returns null and causes exception in main.dart
**Reproduction code
To Reproduce In above code, tag1 and tag2 lines displayed, then, exception occured. Same code was working previously. Now: working on linux but not on windows. Exactly same code works on linux, but not on windows. Apparently, something seems broken.
Expected behavior tag3 line also printed, program should continue.
Screenshots
Flutter Version: flutter --version Flutter 3.13.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 2524052335 (6 days ago) • 2023-09-06 14:32:31 -0700 Engine • revision b8d35810e9 Tools • Dart 3.1.1 • DevTools 2.25.0
Getx Version: 4.6.6
Describe on which device you found the bug: Web-Chrome (On windows only)
Minimal reproduce code as given above