Comments (12)
Thanks for your insights @Hekhy . After analyzing the problem extensively, I've realized that I'm supposed to use a builder to build the child to solve the problem. I've updated the package (^2.0.0) to fix this issue.
from responsive_sizer.
Ah, okay, I didn't know, it's a shame it can't be done, it was so convenient to be able to use it just by calling the ResponsiveSizer widget and sending the child.
Never mind, great job!
from responsive_sizer.
The error occurred because you called 27.sp
before src/helper.dart
was able to execute width = boxConstraints.maxWidth
. How did you use your ThemeData
and did you wrap your MaterialApp
with ResponsiveSizer
widget?
from responsive_sizer.
Hello @CoderUni,
I leave you a link with a test project that I did, where I make a main.dart with a simple page and put the ResponsiveSizer () widget as it is in the example of the package, the theme.dart file is also added, which is the I use to create my theme, if you try it, it should give you the same error as me.
I do not understand why it gives that error, with the other sizer package that is the one before your package it did not give me this problem, so I say that I will use your package in the next app to test it.
Maybe it may be that it is an error because I use the theme as a static variable to be able to call it without having to create an instance in each file where I want to use it (although I only use it in main), but as I have already said I am using it like this with the other packet and the error does not pass.
Here I leave the link to the test project that I mentioned before, so that you can do tests yourself:
https://github.com/Hekhy/responsive_try
from responsive_sizer.
Hello @Hekhy,
The repo you sent here is private. Kindly make the repo public so I could take a look at your test project.
from responsive_sizer.
Oh, sorry, I thought that private meant that only the person who sent the link could see it. I'm new to github and I'm not very good at it yet. Now you should be able to download it.
https://github.com/Hekhy/responsive_try
from responsive_sizer.
@Hekhy The Device.setScreenSize
function in ResponsiveSizer
isn't called before you accessed 27.sp
. You could solve it by wrapping your MaterialApp
with a FutureBuilder
:
return ResponsiveSizer(
child: FutureBuilder(
future: Future.delayed(Duration.zero),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return MaterialApp(
theme: Tema.theme,
from responsive_sizer.
Perfect I will try it like that, although if you could add it as an update, no one will have problems. Thanks for the help :)
from responsive_sizer.
Thanks @Hekhy. I tried placing the FutureBuilder
as part of the ResponsiveSizer
widget. It didn't work because by passing Widget child
<- (in your case, MaterialApp), Tema.theme
gets called even before ResponsiveSizer
gets to build its own widgets. I will add that as an update once I figure out a solution.
from responsive_sizer.
Hello @CoderUni.
Sounds good to me, I'll be attentive to new versions of the package or a possible notification from you, hopefully you can solve it soon.
And to say, not as it criticizes you or your package, but as it criticizes the Dart language, which is a bit strange that in the build of a widget the theme is loaded before the previous widgets as in this case the layoutbuilder.
I don't know exactly how Dart works 100%, but I think it must have something to do with it first reads all the files and the file where the theme is reads it at the same time as the file where the app material is and how it doesn't load to time Device.setScreenSize (constraints, orientation); gives the error.
I suppose you had reached some similar conclusion, but I am telling you because the method used in the other sizer package was different, maybe you can walk there to solve the problem.
I also tried to put your package in my project locally, to be able to make changes and try to help you with the solution, but it can't, in the visual studio code editor it doesn't give me any code errors, apparently everything is fine, but when I launch The application to test gives me errors that make me think that the version of Dart that each of us has is different, maybe the problem can also go there, but I think my version is the last one since a few days ago I updated Flutter and Dart was updated automatically. I will also try to update it if it is not, and I will try again, but I say this hypothesis about the Dart version because when you configure the child argument of the ResposiveSizer widget in its constructor, you put required and I have always used @required, and it is there where is it giving me the error, and even if I change it and put @required it don´t goes well, because I get an error in the editor and it tells me that the child argument cannot be null although calling MaterialApp as the child of ResposiveSizer, I have not managed to fix anything and that was the only change I had made.
I would like to have helped by doing my own tests, but it has not been possible.
from responsive_sizer.
Now it works!! Thank you!
The only thing I'm wondering is why you didn't create the widget like this:
class ResponsiveSizer extends StatelessWidget {
const ResponsiveSizer({Key? key, required child}) : super(key: key);
/// Builds the widget whenever the orientation changes
final Widget child;
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return OrientationBuilder(builder: (context, orientation) {
Device.setScreenSize(constraints, orientation);
builder: (context, orientation, Device.screenType) {
return child;
}
});
});
}
}
That way you could call it like this:
Widget build(BuildContext context) {
return ResponsiveSizer(
child: MaterialApp(
in the same way you had it before but with the added builder and so it is as clean as before, which is one of the things that I love about your package.
Anyway now it works very well.
from responsive_sizer.
@Hekhy You cannot pass a child because you want it to rebuild whenever the orientation changes. This is why certain widgets like LayoutBuilder
and StreamBuilder
use the builder
parameter.
from responsive_sizer.
Related Issues (20)
- How can I make rebuild the screen again when I change the orientation? HOT 3
- Can not use it with provider package.
- tree rebuilds when keyboard shows HOT 1
- How to use responsive sizer when using routes and initialroute instead of home in MaterialApp? HOT 2
- Sizes do not appear to be updating correctly on Windows maximise or restore using WidgetsBindingObserver HOT 1
- ../../../development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/responsive_sizer-3.0.6+1/lib/src/helper.dart:56:33: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null. HOT 3
- App doesn't run correctly when I compile it to Android HOT 12
- Add Desktop ScreenType HOT 5
- two ResponsiveSizer HOT 2
- Sp and Dp way different than with sizer and are not interchangable HOT 7
- Error using any method HOT 1
- Does not reload the screen when the device changes from Portrait to Landscape HOT 2
- The Device Class variables apsectRatio, width, and height all Resize when Textfieldforms are used. HOT 2
- unfocus in flutter 3.10 HOT 1
- Changing the device text size setting affects the outputted UI. HOT 3
- ScreenType.desktop Issue HOT 4
- How to use responsive_sizer to achieve a responsive design using a Figma design with a specified phone frame? HOT 2
- Responsive sizer stops working properly, resizing issues HOT 2
- Is this keep maintained and work with flutter 3.20? HOT 1
- Undefined name 'View'. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from responsive_sizer.