Following are the question which needs to be answered?
1.How to set inset border in Flutter.(already tried Border() but no inset option)
2.How to remove Material statelesswidget from index class. I know that stateful widget and stateless widget both are in the material library.but I need another way through which I can display normal layout without using the stateless or stateful widget.
3.Currently, Flutter doesn't support SVG. is there any other way to put SVG in the layout.
I realize this isn't the best question - in the future try to ask 3 separate questions... but I'm going to answer it as best I can anyways.
1) I'm assuming you mean you want to inset your inner class. There are a few ways to do this, but the easiest is probably to use a container. This shows the inset types (similar-ish to how it works in HTML):
new Container(
margin: const EdgeInsets.all(15.0),
padding: const EdgeInsets.all(3.0),
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)
),
child: ...,
)
2) I don't really understand the question. You don't technically need Stateful & Stateless widgets to be able to make a flutter app - you can simply return a cascade of objects from runApp in your main function... but if you want to display any data or basically do anything, you need to define your own widgets.
The provided widgets are the basic building blocks of a flutter application; they contain logic for layout and rendering in their implementations, whereas your own widgets can almost exclusively use the provided widgets rather than having to understand how that all works. But to keep track of your app's state, you need stateful widgets, and to encapsulate a set of widgets a stateful widget helps a lot! You generally end up with a very nested structure in flutter (which it is optimized for) - a different paradigm from some other frameworks and languages that instead use XML or a structure markup language - but using stateless widgets can help to keep the nesting to a reasonable size.
I highly recommend following the flutter codelab and the other tutorials etc on the flutter.io website as they will show you the basics.
3) Unfortunately, flutter doesn't support SVGs at the moment although there is some discussion on github about supporting them in the future.
I've utilized some vectors in my project by using a CustomPainter + canvas and converting the path/circle/lines to drawCircle, drawPath, drawLine. I've a semi-automated tool for doing that but it's pretty hacky and so not worth releasing at this point. Eventually I'd like to make it into a plugin but that won't be any time soon....
Related
I am trying to animate many widgets such as Text(), Image.asset() and other stuff when they are visible. I tried multiple libraries for checking visibilty of Widgets inside a SingleChildScrollView() but all solutions were either very complicated or it takes a lot of coding to achieve it for multiple widgets. The question that is most similar to mine is this, but it is simple for one or two widgets, but it will be messy for many Widgets. Can someone help me in achieving this requirement?
Edit:
I found that 'flutter_animate' depends on controllers, such as ScrollController, but no documentation about it was mentioned.
enter link description here
I'm newly learning and creating simple app using flutter.
I created drawer inside Scaffold for some pages and I got confused if when I click the ListTiles, should it be routing the pages or just switch the body widget using setState().
I guess setState() must perform better but I'm not sure if this is a good practice for pages. If it does not have a big difference in performance, I would like to use routing the pages since it will be uniformed.
Personal opinion:
Avoid separating widgets into functions, use StatelessWidget instead. Cause every render function will rebuild whatever parameter changes.
Avoid using setState as much as possible, especially for large Widgets, instead use provider, get or simply use ValueNotifier if you dont want library. Cause setState will mark all things to be rerender include widgets that not need to be rerender.
Do not render too many things at once, if possible only render the views that are / are about to be displayed. Example using ListView.builder instead of ListView, ... etc
With image, please resize to suit your needs, a 2000x2000 image loaded as a 24x24 icon is clearly not a good idea.
using const.
I'd suggest to redirect user to the next page as it won't require a StatefulWidget (you can use navigator to navigate user to another activity) which will be lighter to run, as if you use IndexedStack or dynamically assign the widget it'll require the StatefulWidget..
As the below diagram shows Stateful widget covers what Stateless widget do, When I can do the same thing with Stateful widget, why Flutter designers added another widget? For increasing performance?
Please do not post the difference just answer the Why?
Would you always use a sword to do a knife's job? Given that you always have both of them available with easy access. The knife can't do everything a sword can, but would that mean that a sword should be used by default for everything, since it's more robust?
You'll have many widgets where the state of the elements will not change, and others where you will not have to use setState to update your UI either(given that you would rather not use higher level state management solutions).
Using stateless widgets as long as they can do the job, means more performent widget trees.
Please do not post the difference just answer the Why?
Knowing the difference between them is key to understanding 'why', and the differences are not just in the name less vs full. But sensing that you aren't interested, that's why.
Good Flutter code seperates the code into many small Widgets. In addition to better performance creating a StatefulWidget means that you have to write more code and add unnecessary complexity to your code.
For better performance. Stateless widgets are usually only called in one of these three situations:
1- widget is inserted in the tree.
2- Widget's parent changes its configuration
3- Inherited Widget it depends on changes.
I'm currently learning flutter and i quiet appreciate the learnng curve. But I have a challenge. The tutorials i have what they kept more emphasis on reading more about flutter widget on flutter.io to know more about the widget. I have done that but i still dont understand it.
E.g: The container class properties have a decoration property. I went to check it on flutter site and i saw it there. But in the decoration properties flutter didn't add BoxDecoration. So how do one know that BoxDecoration must be called when on is using the decoration property of the Container class.
decoration: BoxDecoration(
color:Colors.teal,
borderRadius:BorderRadius.circular(12,
strong text
The Container.decoration field doesn't expect a BoxDecoration, it expect a Decoration, which can be a BoxDecoration. In Flutter at the time of writing, you can have may Decoration implementation, each one having its use case:
BoxDecoration (of course)
FlutterLogoDecoration
ShapeDecoration
many other Decoration that can be found on the Flutter API...
The way you know what widget should be used depend only on what you want to have, and your use case.
For example, you have a widget (eg. RaisedButton) and you want to apply a ShapeBorder to it. The shape you will choose depend only to form you want your button to have.
It may be a RoundedRectangleBorder to apply a custom border radius, or a StadiumBorder to apply an harmonized elliptic border radius, and so on...
There is definitively no standard way to create or use widgets in Flutter, everything depend on you, and your knowledge :-)
So, you are in Container Class documentation and you see under Properties decoration → Decoration?. Now clicking on Decoration takes to Decoration Class documentation
Here you see on top that it belongs to painting library (Flutter > painting > Decoration abstract class). So, you go to painting library documentation and look for box decoration and you see BoxDecoration as Class.
What is the best practice in flutter for padding,margin etc.
example:
I made a simple drawer in flutter. To make everything to position in places I want. I used padding extensively.
Now the issue is when I test it on different phone of different size. the positions are inconsistent across different devices.
From the Flutter Docs:
Design discussion Why use a Padding widget rather than a Container
with a Container.padding property? There isn't really any difference
between the two. If you supply a Container.padding argument, Container
simply builds a Padding widget for you.
Container doesn't implement its properties directly. Instead,
Container combines a number of simpler widgets together into a
convenient package. For example, the Container.padding property causes
the container to build a Padding widget and the Container.decoration
property causes the container to build a DecoratedBox widget. If you
find Container convenient, feel free to use it. If not, feel free to
build these simpler widgets in whatever combination meets your needs.
In fact, the majority of widgets in Flutter are simply combinations of
other simpler widgets. Composition, rather than inheritance, is the
primary mechanism for building up widgets.
So, no worries about padding widgets.
A good practice to get some spaces inside a Column() or Row() is using SizedBox(). Then you add an extra space setting up width or height.