AppBrewery - Dicee Flashcards
Expanded widget
A widget that expands a child of a Row, Column, or Flex so that the child fills the available space.
Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space along the main axis (e.g., horizontally for a Row or vertically for a Column). If multiple children are expanded, the available space is divided among them according to the flex factor.
An Expanded widget must be a descendant of a Row, Column, or Flex, and the path from the Expanded widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).
similar to flex; set weight with flex: 2
, defaults to flex: 1
Image shorthands
new Image.asset, for obtaining an image from an AssetBundle using a key.
new Image.network, for obtaining an image from a URL.
new Image.file, for obtaining an image from a File.
new Image.memory, for obtaining an image from a Uint8List.
`Image.asset(‘’)
FlatButton()
A material design “flat button”.
A flat button is a text label displayed on a (zero elevation) Material widget that reacts to touches by filling with color.
requires onPressed
child can be anything (?)
Dart (){ // … }
anonymous function
Dart string interpolation
‘ashijf $<var> oaisjf'</var>
put updating vars inside…
and declaration of vars…
build, captured by hot reload
outside build, but property of widget
Dart dynamic data type
Dart is static, but the dynamic data type specifies any type
Although Dart is strongly typed, type annotations are optional because Dart can infer types. In the code above, number is inferred to be of type int. When you want to explicitly say that no type is expected, use the special type dynamic.
var a;
a = 123;
a = 'ok';
// works, because a is dynamic; type not specified on declaration line.
also:
dynamic a = 123;
a = ‘ok’;
Object vs Dynamic
Some operations work with any possible object. For example, a log() method could take any object and call toString() on it. Two types in Dart permit all values: Object and dynamic. However, they convey different things. If you simply want to state that you allow all objects, use Object, as you would in Java or C#.
Using dynamic sends a more complex signal. It may mean that Dart’s type system isn’t sophisticated enough to represent the set of types that are allowed, or that the values are coming from interop or otherwise outside of the purview of the static type system, or that you explicitly want runtime dynamism at that point in the program.
use dynamic?
generally, no. Keep type static safety; avoid var and dynamic
shortcut for StatefulWidget
stful
parts of StatefulWidget
StatefulWidget & StatefulWidgetState
similar parts between stful and stless widgets
the State and the stless widget; both have build
for stateful widget, where + how to set state?
call setState inside State;
setState triggers rebuild
where to declare state?
inside State, outside build.
setState
Notify the framework that the internal state of this object has changed.
Whenever you change the internal state of a State object, make the change in a function that you pass to setState:
Calling setState notifies the framework that the internal state of this object has changed in a way that might impact the user interface in this subtree, which causes the framework to schedule a build for this State object.
When called, app goes thru widget, finds places this state is used, and updates there.