-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smallest Flutter application #63
Comments
The import 'dart:async`; // use dart: to import built-in libraries
import 'package:flutter/materials.dart'; // use package: to import packages via pub
import 'helpers/my_helpers.dart'; //user file path to reference other files in your project The You can create a prefix name for your imports with the import 'dart:async' as async; // To use a method from the async pakcage you can now prefix it with async. You can specify what to import from a package with the import 'dart:async' show Future; // only import the Future class
import 'dart:async' hide Future; // import all from async except Future You can use the import 'lib/my_functions.dart' deferred as my_functions; You will then need to call the Future func() async {
await my_functions.loadLibrary(); //load the library
my_functions.bonjour(); //call the bonjour method
} See also the style guide when importing packages/files: https://dart.dev/guides/language/effective-dart/style#do-name-libraries-and-source-files-using-lowercase_with_underscores references:
|
Similar to the import 'package:flutter/material.dart';
void main() {
runApp(MyApp('hello'));
return runApp(MyApp('hello there!!'));
}
class MyApp extends StatelessWidget {
final String txt;
MyApp(this.txt);
@override
Widget build(BuildContext context) {
return Center( child: Text(txt, textDirection: TextDirection.ltr)
);
}
} In this example the class
|
A widget in Flutter is the configuration of some part of the UI. It describes how the UI element should be displayed on the screen. @immutable
abstract class Widget extends DiagnosticableTree {
/// Initializes [key] for subclasses.
const Widget({ this.key }); Immutability is used with widgets to make it easier to determine which part of the UI needs to be updated. A stateless widget abstract class StatelessWidget extends Widget {
const StatelessWidget({ Key key }) : super(key: key);
@override
StatelessElement createElement() => StatelessElement(this);
@protected
Widget build(BuildContext context);
} The @override
Widget build(BuildContext context) {
return Center( child: Text(txt, textDirection: TextDirection.ltr)
);
} The build method describes the UI part of the widget. The build function is also responsible for creating any child widgets. For example if the Column is used in the build any widgets in the children properties will also be built. This process is repeated until there aren't anymore widget to build in the widget tree. This process is used to create widget composition. |
// import the material package
// add the package in pubspec.yaml file and use the pub get command line
import 'package:flutter/material.dart';
// void main() => runApp(MyApp());
// this arrow syntax is the same as
void main() {
return runApp(MyApp()); //runApp returns void, so main has also void as returned type, https://api.flutter.dev/flutter/widgets/runApp.html
{
class MyApp extends StatelessWidget { // MyApp is a subclass of StatelesWidget
// the implementation of build is required on a stateless widget
// redefine the build function inherited from StatelessWidget
//the context describe where the MyApp widget is on the widget tree
@override
Widget build(BuildContext context) {
// the child is a Text Widget. MyApp widget is then composed of a child text widget
return Center( child: Text('hello', textDirection: TextDirection.ltr)
);
}
} |
The small following example contains already multiple Flutter/Dart and OOP concepts.
I'll try to explain them which hopefully will allow us to fully understand how this application works.
The text was updated successfully, but these errors were encountered: