How do one identify the required widget class properties in flutter - flutter

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.

Related

Change another widget with a checkbox Flutter

I'm new to Flutter and I found a pretty cool design of a todoapp on Dribble so I wanted to create the app.
Here's the design :
I wonder how with the my callBack Function of my CheckBox I could change the color of the text part of the tile to this blue.
My tile is currently a row containing a checkbox and a Container with the text in. So I would like to when i click on the checkbox, the background color of my container turns to blue.
I dont' have a any idea how to do that.
If you have some ideas please tell me.
Flutter apps work with app states, these states contain the information about the screens pushed by the app.
What you need to do is to update the state of your current widget, and change the values that set that background to X color.
Here you have multiple docs about state management: https://flutter.dev/docs/development/data-and-backend/state-mgmt/options, I really recommend for beginners to start with the setState method as is the easiest one.
Also, if you don't know how to manage states I will really recommend to follow the docs to understand how widget works and are build over flutter apps: https://flutter.dev/docs/development/ui/widgets-intro
Well, I just needded to put this in the color property of my container knowing that isChecked is true when my checkbox is clicked.
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius : BorderRadius.circular(15),
color: widget.isChecked ? Color(0xFF2765f9) : Color(0xFF292E3C),

design a complex card in the flutter

What is the best way to design the following card?
I do not know use card or design it with (container/row/column/....)
How can I achieve that?
I think the information is too rough to give the advice. Though Card Widget is easy to use but lots of properties are not able to change (like border, shadow of the card). I suggest
you can study the Card widget first and define a custom card widget if it is not fit your layout.
For custom widget, I think container/row/column can do most of the layout. Only the avatar may need to use BoxDecoration(also in Container) or ClipOval. Setting can use Stack widget (need to overlay).

What's the difference between raisedButton and Container with onTap() (Flutter)?

When we want to achieve a button, we can choose raisedButton in flutter lib, also can a Container with onTap() function. So what's the difference between the two and which one should we choose in different situation?
Container function doesnot have onTap option, but you can achieve it by wrapping it in Guesture detector or Inkwell. There are no changes in the backend. But Raised button gives you the elevation, and animation on tap. You can also do it in the container, but it requires you to manually do it.
If you want a simple button quickly use RaisedButton.
If you want a more complex one, use Container or mixture of Containers, RaisedButton etc.
I am gonna offer something different... A tale of a treasure that is known to have answers to many questions, use cases and sometimes even examples. The name of this treasure is: official documentation. ;)
RaisedButton
A raised button is based on a Material widget whose Material.elevation increases when the button is pressed. Use raised buttons to add dimension to otherwise mostly flat layouts, e.g. in long busy lists of content, or in wide spaces. Avoid using raised buttons on already-raised content such as dialogs or cards.
Container
A convenience widget that combines common painting, positioning, and
sizing widgets.
GestureDetector
A widget that detects gestures. Attempts to recognize gestures that
correspond to its non-null callbacks. If this widget has a child, it
defers to that child for its sizing behavior. If it does not have a
child, it grows to fit the parent instead. By default a
GestureDetector with an invisible child ignores touches; this behavior
can be controlled with behavior. GestureDetector also listens for
accessibility events and maps them to the callbacks. To ignore
accessibility events, set excludeFromSemantics to true. See
flutter.dev/gestures/ for additional information. Material design
applications typically react to touches with ink splash effects. The
InkWell class implements this effect and can be used in place of a
GestureDetector for handling taps.
InkWell
A rectangular area of a Material that responds to touch. For a variant
of this widget that does not clip splashes, see InkResponse... The
InkWell widget must have a Material widget as an ancestor. The
Material widget is where the ink reactions are actually painted. This
matches the material design premise wherein the Material is what is
actually reacting to touches by spreading ink.
Well, technically you are right, they can both react to a click event. But a RaisedButton will have all the styles specific to the target platform taken care of for you (it inherits from MaterialButton).
note that it's the same in html: you can use a regular div with a click handler or use a button tag. The button will have a few styles already taken care of for you...

Things to be aware of when using a container as a parent instead of MaterialApp/Scaffold

Say I'm building an app that doesn't need Material design elements and use a container as a parent.
Are there things that need to be set up manually (layout-wise) that's unnecessary when using MaterialApp/Scaffold?
Following are few unexpected behaviors I noticed when using a container as a parent:
• Yellow lines in Text widgets (These lines disappear when using Scaffold instead)
• ClipRRect widget takes up the full screen even when I set constraints
Material class is a main component of your UI. Using a Material Widget as parent doesn't mean you are forced to use Material Design for your entire app, you can do your own custom Widgets, UI, etc.
As part of the official documentation:
The Material widget is responsible for:
Clipping: If clipBehavior is not Clip.none, Material clips its widget sub-tree to the shape specified by shape, type, and borderRadius. By default, clipBehavior is Clip.none for performance considerations.
Elevation: Material elevates its widget sub-tree on the Z axis by elevation pixels, and draws the appropriate shadow.
Ink effects: Material shows ink effects implemented by InkFeatures like InkSplash and InkHighlight below its children.
It is also responsible of providing default styles for your Texts (that's why you're seeing the yellow underline).
Still, remember that you're making apps for mobile clients, therefore, you should be using some of the best practices that MaterialApp and CupertinoApp bring out of the box, even if you decide to take your own path inside the app, using your own custom Widgets, etc

Flutter Basic Information

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....