1. What every programme starts with void main() => runApp( new MyApp()); "=>" is an operator and it denotes { return expr ; } . () denotes method runApp will run MyApp() which is a widget. Besides running MyApp(), you can also play with runApp() function by doing the following: new Text(). Do remember to include the TextDirection. Text will appear on the top left hand corner of the screen. void main() { runApp( new Text( 'Hello World' ,textDirection: TextDirection. ltr ,)); } Make it centralised in the center through the following. void main() => runApp( new Center( child: new Text( 'Hello World' ,textDirection: TextDirection. ltr ,) ) ); 2.Declaring App/Widget to be run in runApp() void main() => runApp(MyApp()); class MyApp extends StatelessWidget{ @override Widget build(BuildContext context) { // TODO: implement build return null ; } } extends is the inheriting of...
1. Aim Through Snackbar, understand Context and how to use builder to access any context of a widget. 2.Snackbar Code from Codelab If you use Scaffold.of(context), there will be Context Error "Scaffold.of() called with a context that does not contain a Scaffold" import 'package:flutter/material.dart' ; void main() { runApp( new MaterialApp(home: new SnackApp())); } class SnackApp extends StatefulWidget { @override _SnackAppState createState() => _SnackAppState(); } class _SnackAppState extends State<SnackApp> { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text( "Snackbar exercise" ), ), body: new Center( child: new RaisedButton( onPressed: (){ final snackBar = SnackBar(content: Text( 'Yay! A SnackBar!' )); Scaffold. of (context).showSnackBar(snackBar); }, ...
Comments
Post a Comment