id
stringlengths
14
17
text
stringlengths
23
1.11k
source
stringlengths
35
114
8fc93dc296ae-13
You can access your strings as such: By default, Flutter only supports US English for its strings. If you need to add support for other languages, include the flutter_localizations package. You might also need to add Dart’s intl package to use i10n machinery, such as date/time formatting. dependencies flutter_localizations sdk flutter intl ^0.17.0' To use the flutter_localizations package, specify the localizationsDelegates and supportedLocales on the app widget:
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-14
The delegates contain the actual localized values, while the supportedLocales defines which locales the app supports. The above example uses a MaterialApp, so it has both a GlobalWidgetsLocalizations for the base widgets localized values, and a MaterialWidgetsLocalizations for the Material widgets localizations. If you use WidgetsApp for your app, you don’t need the latter. Note that these two delegates contain “default” values, but you’ll need to provide one or more delegates for your own app’s localizable copy, if you want those to be localized too. Localizations widget for you, with the delegates you specify. The current locale for the device is always accessible from the Window.locale.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-15
Window.locale. To access localized resources, use the Localizations.of() method to access a specific localizations class that is provided by a given delegate. Use the intl_translation package to extract translatable copy to arb files for translating, and importing them back into the app for using them with intl. For further details on internationalization and localization in Flutter, see the internationalization guide, which has sample code with and without the intl package. Managing dependencies In iOS, you add dependencies with CocoaPods by adding to your Podfile. Flutter uses Dart’s build system and the Pub package manager to handle dependencies. The tools delegate the building of the native Android and iOS wrapper apps to the respective build systems.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-16
While there is a Podfile in the iOS folder in your Flutter project, only use this if you are adding native dependencies needed for per-platform integration. In general, use pubspec.yaml to declare external dependencies in Flutter. A good place to find great packages for Flutter is on pub.dev. ViewControllers This section of the document discusses the equivalent of ViewController in Flutter and how to listen to lifecycle events. Equivalent of ViewController in Flutter In UIKit, a ViewController represents a portion of user interface, most commonly used for a screen or section. These are composed together to build complex user interfaces, and help scale your application’s UI. In Flutter, this job falls to Widgets. As mentioned in the Navigation section, screens in Flutter are represented by Widgets since “everything is a widget!” Use a Navigator to move between different Routes that represent different screens or pages, or maybe different states or renderings of the same data.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-17
Listening to lifecycle events In UIKit, you can override methods to the ViewController to capture lifecycle methods for the view itself, or register lifecycle callbacks in the AppDelegate. In Flutter, you have neither concept, but you can instead listen to lifecycle events by hooking into the WidgetsBinding observer and listening to the didChangeAppLifecycleState() change event. The observable lifecycle events are: The application is in an inactive state and is not receiving user input. This event only works on iOS, as there is no equivalent event on Android. The application is not currently visible to the user, is not responding to user input, but is running in the background. The application is visible and responding to user input. The application is suspended momentarily. The iOS platform has no equivalent event. For more details on the meaning of these states, see AppLifecycleState documentation. Layouts
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-18
Layouts This section discusses different layouts in Flutter and how they compare with UIKit. Displaying a list view In UIKit, you might show a list in either a UITableView or a UICollectionView. In Flutter, you have a similar implementation using a ListView. In UIKit, these views have delegate methods for deciding the number of rows, the cell for each index path, and the size of the cells. Due to Flutter’s immutable widget pattern, you pass a list of widgets to your ListView, and Flutter takes care of making sure that scrolling is fast and smooth. Detecting what was clicked In UIKit, you implement the delegate method, tableView:didSelectRowAtIndexPath:. In Flutter, use the touch handling provided by the passed-in widgets. Dynamically updating ListView
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-19
Dynamically updating ListView In UIKit, you update the data for the list view, and notify the table or collection view using the reloadData method. In Flutter, if you update the list of widgets inside a setState(), you quickly see that your data doesn’t change visually. This is because when setState() is called, the Flutter rendering engine looks at the widget tree to see if anything has changed. When it gets to your ListView, it performs an == check, and determines that the two ListViews are the same. Nothing has changed, so no update is required. For a simple way to update your ListView, create a new List inside of setState(), and copy the data from the old list to the new list. While this approach is simple, it is not recommended for large data sets, as shown in the next example.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-20
The recommended, efficient, and effective way to build a list uses a ListView.Builder. This method is great when you have a dynamic list or a list with very large amounts of data. Instead of creating a ListView, create a ListView.builder that takes two key parameters: the initial length of the list, and an ItemBuilder function. The ItemBuilder function is similar to the cellForItemAt delegate method in an iOS table or collection view, as it takes a position, and returns the cell you want rendered at that position. Finally, but most importantly, notice that the onTap() function doesn’t recreate the list anymore, but instead .adds to it. Creating a scroll view In UIKit, you wrap your views in a ScrollView that allows a user to scroll your content if needed. In Flutter the easiest way to do this is using the ListView widget. This acts as both a ScrollView and an iOS TableView, as you can layout widgets in a vertical format.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-21
For more detailed docs on how to lay out widgets in Flutter, see the layout tutorial. Gesture detection and touch event handling This section discusses how to detect gestures and handle different events in Flutter, and how they compare with UIKit. Adding a click listener In UIKit, you attach a GestureRecognizer to a view to handle click events. In Flutter, there are two ways of adding touch listeners: If the widget supports event detection, pass a function to it, and handle the event in the function. For example, the ElevatedButton widget has an onPressed parameter: @override Widget build(BuildContext context) { return ElevatedButton( onPressed: () { developer.log('click'); }, child: const Text('Button'), ); }
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-22
If the Widget doesn’t support event detection, wrap the widget in a GestureDetector and pass a function to the onTap parameter. class SampleTapApp extends StatelessWidget { const SampleTapApp({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: GestureDetector( onTap: () { developer.log('tap'); }, child: const FlutterLogo( size: 200.0, ), ), ), ); } } Handling other gestures Using GestureDetector you can listen to a wide range of gestures such as: Tapping
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-23
Tapping onTapDown A pointer that might cause a tap has contacted the screen at a particular location. onTapUp A pointer that triggers a tap has stopped contacting the screen at a particular location. onTap A tap has occurred. onTapCancel The pointer that previously triggered the onTapDown won’t cause a tap. Double tapping onDoubleTap The user tapped the screen at the same location twice in quick succession. Long pressing onLongPress A pointer has remained in contact with the screen at the same location for a long period of time. Vertical dragging
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-24
Vertical dragging onVerticalDragStart A pointer has contacted the screen and might begin to move vertically. onVerticalDragUpdate A pointer in contact with the screen has moved further in the vertical direction. onVerticalDragEnd A pointer that was previously in contact with the screen and moving vertically is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen. Horizontal dragging onHorizontalDragStart A pointer has contacted the screen and might begin to move horizontally. onHorizontalDragUpdate A pointer in contact with the screen has moved further in the horizontal direction. onHorizontalDragEnd A pointer that was previously in contact with the screen and moving horizontally is no longer in contact with the screen. The following example shows a GestureDetector that rotates the Flutter logo on a double tap: Themes, styles, and media
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-25
Themes, styles, and media Flutter applications are easy to style; you can switch between light and dark themes, change the style of your text and UI components, and more. This section covers aspects of styling your Flutter apps and compares how you might do the same in UIKit. Using a theme Out of the box, Flutter comes with a beautiful implementation of Material Design, which takes care of a lot of styling and theming needs that you would typically do. To take full advantage of Material Components in your app, declare a top-level widget, MaterialApp, as the entry point to your application. MaterialApp is a convenience widget that wraps a number of widgets that are commonly required for applications implementing Material Design. It builds upon a WidgetsApp by adding Material specific functionality.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-26
But Flutter is flexible and expressive enough to implement any design language. On iOS, you can use the Cupertino library to produce an interface that adheres to the Human Interface Guidelines. For the full set of these widgets, see the Cupertino widgets gallery. You can also use a WidgetsApp as your app widget, which provides some of the same functionality, but is not as rich as MaterialApp. To customize the colors and styles of any child components, pass a ThemeData object to the MaterialApp widget. For example, in the code below, the primary swatch is set to blue and divider color is grey. Using custom fonts In UIKit, you import any ttf font files into your project and create a reference in the info.plist file. In Flutter, place the font file in a folder and reference it in the pubspec.yaml file, similar to how you import images. fonts family
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-27
fonts family MyCustomFont fonts asset fonts/MyCustomFont.ttf style italic Then assign the font to your Text widget: Styling text Along with fonts, you can customize other styling elements on a Text widget. The style parameter of a Text widget takes a TextStyle object, where you can customize many parameters, such as: color decoration decorationColor decorationStyle fontFamily fontSize fontStyle fontWeight hashCode height inherit letterSpacing textBaseline wordSpacing Bundling images in apps
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-28
wordSpacing Bundling images in apps While iOS treats images and assets as distinct items, Flutter apps have only assets. Resources that are placed in the Images.xcasset folder on iOS, are placed in an assets’ folder for Flutter. As with iOS, assets are any type of file, not just images. For example, you might have a JSON file located in the my-assets folder: Declare the asset in the pubspec.yaml file: assets my-assets/data.json And then access it from code using an AssetBundle: For images, Flutter follows a simple density-based format like iOS. Image assets might be 1.0x, 2.0x, 3.0x, or any other multiplier. The so-called devicePixelRatio expresses the ratio of physical pixels in a single logical pixel.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-29
Assets are located in any arbitrary folder— Flutter has no predefined folder structure. You declare the assets (with location) in the pubspec.yaml file, and Flutter picks them up. For example, to add an image called my_icon.png to your Flutter project, you might decide to store it in a folder arbitrarily called images. Place the base image (1.0x) in the images folder, and the other variants in sub-folders named after the appropriate ratio multiplier: Next, declare these images in the pubspec.yaml file: assets images/my_icon.png You can now access your images using AssetImage: or directly in an Image widget: For more details, see Adding Assets and Images in Flutter. Form input This section discusses how to use forms in Flutter and how they compare with UIKit. Retrieving user input
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-30
Retrieving user input Given how Flutter uses immutable widgets with a separate state, you might be wondering how user input fits into the picture. In UIKit, you usually query the widgets for their current values when it’s time to submit the user input, or action on it. How does that work in Flutter? In practice forms are handled, like everything in Flutter, by specialized widgets. If you have a TextField or a TextFormField, you can supply a TextEditingController to retrieve user input: You can find more information and the full code listing in Retrieve the value of a text field, from the Flutter cookbook. Placeholder in a text field In Flutter, you can easily show a “hint” or a placeholder text for your field by adding an InputDecoration object to the decoration constructor parameter for the Text widget: Showing validation errors
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-31
Showing validation errors Just as you would with a “hint”, pass an InputDecoration object to the decoration constructor for the Text widget. However, you don’t want to start off by showing an error. Instead, when the user has entered invalid data, update the state, and pass a new InputDecoration object. Threading & asynchronicity This section discusses concurrency in Flutter and how it compares with UIKit. Writing asynchronous code Dart has a single-threaded execution model, with support for Isolates (a way to run Dart code on another thread), an event loop, and asynchronous programming. Unless you spawn an Isolate, your Dart code runs in the main UI thread and is driven by an event loop. Flutter’s event loop is equivalent to the iOS main loop—that is, the Looper that is attached to the main thread.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-32
Dart’s single-threaded model doesn’t mean you are required to run everything as a blocking operation that causes the UI to freeze. Instead, use the asynchronous facilities that the Dart language provides, such as async/await, to perform asynchronous work. For example, you can run network code without causing the UI to hang by using async/await and letting Dart do the heavy lifting: Once the awaited network call is done, update the UI by calling setState(), which triggers a rebuild of the widget sub-tree and updates the data. The following example loads data asynchronously and displays it in a ListView: Refer to the next section for more information on doing work in the background, and how Flutter differs from iOS. Moving to the background thread
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-33
Moving to the background thread Since Flutter is single threaded and runs an event loop (like Node.js), you don’t have to worry about thread management or spawning background threads. If you’re doing I/O-bound work, such as disk access or a network call, then you can safely use async/await and you’re done. If, on the other hand, you need to do computationally intensive work that keeps the CPU busy, you want to move it to an Isolate to avoid blocking the event loop. For I/O-bound work, declare the function as an async function, and await on long-running tasks inside the function: This is how you typically do network or database calls, which are both I/O operations. However, there are times when you might be processing a large amount of data and your UI hangs. In Flutter, use Isolates to take advantage of multiple CPU cores to do long-running or computationally intensive tasks.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-34
Isolates are separate execution threads that do not share any memory with the main execution memory heap. This means you can’t access variables from the main thread, or update your UI by calling setState(). Isolates are true to their name, and cannot share memory (in the form of static fields, for example). The following example shows, in a simple isolate, how to share data back to the main thread to update the UI. Here, dataLoader() is the Isolate that runs in its own separate execution thread. In the isolate, you can perform more CPU intensive processing (parsing a big JSON, for example), or perform computationally intensive math, such as encryption or signal processing. You can run the full example below: Making network requests Making a network call in Flutter is easy when you use the popular http package. This abstracts away a lot of the networking that you might normally implement yourself, making it simple to make network calls.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
8fc93dc296ae-35
To use the http package, add it to your dependencies in pubspec.yaml: dependencies http ^0.13.4 To make a network call, call await on the async function http.get(): Showing the progress on long running tasks In UIKit, you typically use a UIProgressView while executing a long-running task in the background. In Flutter, use a ProgressIndicator widget. Show the progress programmatically by controlling when it’s rendered through a boolean flag. Tell Flutter to update its state before your long-running task starts, and hide it after it ends. In the example below, the build function is separated into three different functions. If showLoadingDialog is true (when widgets.length == 0), then render the ProgressIndicator. Otherwise, render the ListView with the data returned from a network call.
https://docs.flutter.dev/get-started/flutter-for/uikit-devs/index.html
ceb73c7ad36f-0
Flutter for web developers Performing basic layout operations Styling and aligning text Setting background color Centering components Setting container width Manipulating position and size Setting absolute position Rotating components Scaling components Applying a linear gradient Vertical gradient Horizontal gradient Manipulating shapes Rounding corners Adding box shadows Making circles and ellipses Manipulating text Adjusting text spacing Making inline formatting changes Creating text excerpts This page is for users who are familiar with the HTML and CSS syntax for arranging components of an application’s UI. It maps HTML/CSS code snippets to their Flutter/Dart code equivalents.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-1
Flutter is a framework for building cross-platform applications that uses the Dart programming language. To understand some differences between programming with Dart and programming with Javascript, see Learning Dart as a JavaScript Developer. One of the fundamental differences between designing a web layout and a Flutter layout, is learning how constraints work, and how widgets are sized and positioned. To learn more, see Understanding constraints. The examples assume: The HTML document starts with <!DOCTYPE html>, and the CSS box model for all HTML elements is set to border-box, for consistency with the Flutter model. { box-sizing: border-box; } In Flutter, the default styling of the ‘Lorem ipsum’ text is defined by the bold24Roboto variable as follows, to keep the syntax simple:
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-2
TextStyle bold24Roboto = const TextStyle( color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold, ); How is react-style, or declarative, programming different from the traditional imperative style? For a comparison, see Introduction to declarative UI. Performing basic layout operations The following examples show how to perform the most common UI layout tasks. Styling and aligning text Font style, size, and other text attributes that CSS handles with the font and color properties are individual properties of a TextStyle child of a Text widget. For text-align property in CSS that is used for aligning text, there is a textAlign property of a Text widget. In both HTML and Flutter, child elements or widgets are anchored at the top left, by default. font: 900 24px Georgia; }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-3
font: 900 24px Georgia; } TextStyle( fontFamily: 'Georgia', fontSize: 24, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center, ), ); Setting background color In Flutter, you set the background color using the color property or the decoration property of a Container. However, you cannot supply both, since it would potentially result in the decoration drawing over the background color. The color property should be preferred when the background is a simple color. For other cases, such as gradients or images, use the decoration property. The CSS examples use the hex color equivalents to the Material color palette.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-4
The CSS examples use the hex color equivalents to the Material color palette. background-color: #e0e0e0; /* grey 300 */ width: 320px; height: 240px; font: 900 24px Roboto; } color: Colors.grey[300], child: Text( 'Lorem ipsum', style: bold24Roboto, ), ); decoration: BoxDecoration( color: Colors.grey[300], ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ); Centering components A Center widget centers its child both horizontally and vertically.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-5
A Center widget centers its child both horizontally and vertically. To accomplish a similar effect in CSS, the parent element uses either a flex or table-cell display behavior. The examples on this page show the flex behavior. display: flex; align-items: center; justify-content: center; } Center( child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ); Setting container width Container widget, use its BoxConstraints widget with a For nested Containers, if the parent’s width is less than the child’s width, the child Container sizes itself to match the parent.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-6
width: 320px; height: 240px; font: 900 24px Roboto; display: flex; align-items: center; justify-content: center; } .red-box { background-color: #ef5350; /* red 400 */ padding: 16px; color: #ffffff; width: 100%; max-width: 240px; } width: 320, height: 240, color: Colors.grey[300], child: Center( child: Container( // red box
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-7
width: 240, // max-width is 240 padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.red[400], ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ); Manipulating position and size The following examples show how to perform more complex operations on widget position, size, and background. Setting absolute position By default, widgets are positioned relative to their parent. To specify an absolute position for a widget as x-y coordinates, nest it in a Positioned widget that is, in turn, nested in a Stack widget.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-8
position: relative; background-color: #e0e0e0; /* grey 300 */ width: 320px; height: 240px; font: 900 24px Roboto; } .red-box { background-color: #ef5350; /* red 400 */ padding: 16px; color: #ffffff; position: absolute; top: 24px; left: 24px; } child: Stack( children: [ Positioned( // red box
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-9
child: Stack( children: [ Positioned( // red box left: 24, top: 24, child: Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.red[400], ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ], ), ); Rotating components To rotate a widget, nest it in a Transform widget. Use the Transform widget’s alignment and origin properties to specify the transform origin (fulcrum) in relative and absolute terms, respectively. For a simple 2D rotation, in which the widget is rotated on the Z axis, create a new Matrix4 identity object and use its rotateZ() method to specify the rotation factor using radians (degrees × π / 180).
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-10
transform: rotate(15deg); } Transform( alignment: Alignment.center, transform: Matrix4.identity()..rotateZ(15 * 3.1415927 / 180), child: Container( // red box padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.red[400], ), child: Text( 'Lorem ipsum', style: bold24Roboto, textAlign: TextAlign.center, ), ), ), ), ); Scaling components To scale a widget up or down, nest it in a Transform widget. Use the Transform widget’s alignment and origin properties to specify the transform origin (fulcrum) in relative or absolute terms, respectively.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-11
For a simple scaling operation along the x-axis, create a new Matrix4 identity object and use its scale() method to specify the scaling factor. When you scale a parent widget, its child widgets are scaled accordingly. transform: scale(1.5); } Transform( alignment: Alignment.center, transform: Matrix4.identity()..scale(1.5), child: Container( // red box padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.red[400], ), child: Text( 'Lorem ipsum', style: bold24Roboto, textAlign: TextAlign.center, ), ), ), ), ); Applying a linear gradient Container widget. Then use the BoxDecoration object, and use
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-12
Container widget. Then use the BoxDecoration object, and use The gradient “angle” is based on the Alignment (x, y) values: If the beginning and ending x values are equal, the gradient is vertical (0° | 180°). If the beginning and ending y values are equal, the gradient is horizontal (90° | 270°). Vertical gradient background: linear-gradient(180deg, #ef5350, rgba(0, 0, 0, 0) 80%); }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-13
decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment(0.0, 0.6), colors: <Color>[ Color(0xffef5350), Color(0x00ef5350), ], ), ), padding: const EdgeInsets.all(16), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ); Horizontal gradient background: linear-gradient(90deg, #ef5350, rgba(0, 0, 0, 0) 80%); }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-14
decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment(-1.0, 0.0), end: Alignment(0.6, 0.0), colors: <Color>[ Color(0xffef5350), Color(0x00ef5350), ], ), ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ); Manipulating shapes The following examples show how to make and customize shapes. Rounding corners To round the corners of a rectangular shape, use the borderRadius property of a BoxDecoration object. Create a new BorderRadius object that specifies the radius for rounding each corner. border-radius: 8px; }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-15
border-radius: 8px; } borderRadius: const BorderRadius.all( Radius.circular(8), ), ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ); Adding box shadows In CSS you can specify shadow offset and blur in shorthand, using the box-shadow property. This example shows two box shadows, with properties: xOffset: 0px, yOffset: 2px, blur: 4px, color: black @80% alpha xOffset: 0px, yOffset: 06x, blur: 20px, color: black @50% alpha
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-16
In Flutter, each property and value is specified separately. Use the boxShadow property of BoxDecoration to create a list of BoxShadow widgets. You can define one or multiple BoxShadow widgets, which can be stacked to customize the shadow depth, color, and so on. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 6px 20px rgba(0, 0, 0, 0.5); }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-17
boxShadow: const <BoxShadow>[ BoxShadow( color: Color(0xcc000000), offset: Offset(0, 2), blurRadius: 4, ), BoxShadow( color: Color(0x80000000), offset: Offset(0, 6), blurRadius: 20, ), ], ), child: Text( 'Lorem ipsum', style: bold24Roboto, ), ), ), ); Making circles and ellipses Making a circle in CSS requires a workaround of applying a border-radius of 50% to all four sides of a rectangle, though there are basic shapes. While this approach is supported with the borderRadius property of BoxDecoration, Flutter provides a shape property with BoxShape enum for this purpose.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-18
text-align: center; width: 160px; height: 160px; border-radius: 50%; } shape: BoxShape.circle, ), padding: const EdgeInsets.all(16), width: 160, height: 160, child: Text( 'Lorem ipsum', style: bold24Roboto, textAlign: TextAlign.center, ), ), ), ); Manipulating text The following examples show how to specify fonts and other text attributes. They also show how to transform text strings, customize spacing, and create excerpts. Adjusting text spacing
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-19
Adjusting text spacing In CSS, you specify the amount of white space between each letter or word by giving a length value for the letter-spacing and word-spacing properties, respectively. The amount of space can be in px, pt, cm, em, etc. In Flutter, you specify white space as logical pixels (negative values are allowed) for the letterSpacing and wordSpacing properties of a TextStyle child of a Text widget. letter-spacing: 4px; } letterSpacing: 4, ), ), ), ), ); Making inline formatting changes A Text widget lets you display text with some formatting characteristics. To display text that uses multiple styles (in this example, a single word with emphasis), use a RichText widget instead. Its text property can specify one or more TextSpan objects that can be individually styled.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-20
In the following example, “Lorem” is in a TextSpan with the default (inherited) text styling, and “ipsum” is in a separate TextSpan with custom styling. Lorem <em>ipsum</em> </div> </div> .grey-box { background-color: #e0e0e0; /* grey 300 */ width: 320px; height: 240px; font: 900 24px Roboto; display: flex; align-items: center; justify-content: center; } .red-box { background-color: #ef5350; /* red 400 */ padding: 16px; color: #ffffff; } .red-box em { font: 300 48px Roboto; font-style: italic; }
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-21
RichText( text: TextSpan( style: bold24Roboto, children: const <TextSpan>[ TextSpan(text: 'Lorem '), TextSpan( text: 'ipsum', style: TextStyle( fontWeight: FontWeight.w300, fontStyle: FontStyle.italic, fontSize: 48, ), ), ], ), ), ), ), ); Creating text excerpts An excerpt displays the initial line(s) of text in a paragraph, and handles the overflow text, often using an ellipsis. In Flutter, use the maxLines property of a Text widget to specify the number of lines to include in the excerpt, and the overflow property for handling overflow text.
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
ceb73c7ad36f-22
overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; } overflow: TextOverflow.ellipsis, maxLines: 1, ), ), ), );
https://docs.flutter.dev/get-started/flutter-for/web-devs/index.html
2916fac8cda4-0
Flutter for Xamarin.Forms developers Project setup How does the app start? How do you create a page? Views What is the equivalent of a Page or Element in Flutter? How do I update widgets? How do I lay out my widgets? What is the equivalent of an XAML file? How do I add or remove an Element from my layout? How do I animate a widget? How do I draw/paint on the screen? Where is the widget’s opacity? How do I build custom widgets? Navigation How do I navigate between pages? How do I navigate to another app? Async UI What is the equivalent of Device.BeginOnMainThread() in Flutter? How do you move work to a background thread? How do I make network requests? How do I show the progress for a long-running task? Project structure & resources
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-1
Project structure & resources Where do I store my image files? Where do I store strings? How do I handle localization? Where is my project file? What is the equivalent of Nuget? How do I add dependencies? Application lifecycle How do I listen to application lifecycle events? Layouts What is the equivalent of a StackLayout? What is the equivalent of a Grid? What is the equivalent of a ScrollView? How do I handle landscape transitions in Flutter? Gesture detection and touch event handling How do I add GestureRecognizers to a widget in Flutter? How do I handle other gestures on widgets? Listviews and adapters What is the equivalent to a ListView in Flutter? How do I know which list item has been clicked? How do I update a ListView dynamically? Working with text
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-2
Working with text How do I set custom fonts on my text widgets? How do I style my text widgets? Form input How do I retrieve user input? What is the equivalent of a Placeholder on an Entry? How do I show validation errors? Flutter plugins Interacting with hardware, third party services, and the platform How do I interact with the platform, and with platform native code? How do I access the GPS sensor? How do I access the camera? How do I log in with Facebook? How do I use Firebase features? How do I build my own custom native integrations? Themes (Styles) How do I theme my app? Databases and local storage How do I access shared preferences or UserDefaults? How do I access SQLite in Flutter? Debugging What tools can I use to debug my app in Flutter?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-3
What tools can I use to debug my app in Flutter? Notifications How do I set up push notifications? This document is meant for Xamarin.Forms developers looking to apply their existing knowledge to build mobile apps with Flutter. If you understand the fundamentals of the Xamarin.Forms framework, then you can use this document as a jump start to Flutter development. Your Android and iOS knowledge and skill set are valuable when building with Flutter, because Flutter relies on the native operating system configurations, similar to how you would configure your native Xamarin.Forms projects. The Flutter Frameworks is also similar to how you create a single UI, that is used on multiple platforms. This document can be used as a cookbook by jumping around and finding questions that are most relevant to your needs. Project setup How does the app start?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-4
Project setup How does the app start? For each platform in Xamarin.Forms, you call the LoadApplication method, which creates a new application and starts your app. LoadApplication new App ()); In Flutter, the default main entry point is main where you load your Flutter app. In Xamarin.Forms, you assign a Page to the MainPage property in the Application class. public class App Application public App () MainPage new ContentPage Content new Label Text "Hello World" HorizontalOptions LayoutOptions Center VerticalOptions
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-5
LayoutOptions Center VerticalOptions LayoutOptions Center }; In Flutter, “everything is a widget”, even the application itself. The following example shows MyApp, a simple application Widget. How do you create a page? Xamarin.Forms has many types of pages; ContentPage is the most common. In Flutter, you specify an application widget that holds your root page. You can use a MaterialApp widget, which supports Material Design, or you can use a CupertinoApp widget, which supports an iOS-style app, or you can use the lower level WidgetsApp, which you can customize in any way you want. The following code defines the home page, a stateful widget. In Flutter, all widgets are immutable, but two types of widgets are supported: Stateful and Stateless. Examples of a stateless widget are titles, icons, or images.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-6
The following example uses MaterialApp, which holds its root page in the home property. From here, your actual first page is another Widget, in which you create your state. A Stateful widget, such as MyHomePage below, consists of two parts. The first part, which is itself immutable, creates a State object that holds the state of the object. The State object persists over the life of the widget. The State object implements the build() method for the stateful widget. When the state of the widget tree changes, call setState(), which triggers a build of that portion of the UI. Make sure to call setState() only when necessary, and only on the part of the widget tree that has changed, or it can result in poor UI performance. In Flutter, the UI (also known as widget tree), is immutable, meaning you can’t change its state once it’s built. You change fields in your State class, then call setState() to rebuild the entire widget tree again.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-7
This way of generating UI is different from Xamarin.Forms, but there are many benefits to this approach. Views What is the equivalent of a Page or Element in Flutter? How is react-style, or declarative, programming different from the traditional imperative style? For a comparison, see Introduction to declarative UI. In Flutter, almost everything is a widget. A Page, called a Route in Flutter, is a widget. Buttons, progress bars, and animation controllers are all widgets. When building a route, you create a widget tree. Flutter includes the Material Components library. These are widgets that implement the Material Design guidelines. Material Design is a flexible design system optimized for all platforms, including iOS. But Flutter is flexible and expressive enough to implement any design language. For example, on iOS, you can use the Cupertino widgets to produce an interface that looks like Apple’s iOS design language.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-8
How do I update widgets? In Xamarin.Forms, each Page or Element is a stateful class, that has properties and methods. You update your Element by updating a property, and this is propagated down to the native control. In Flutter, Widgets are immutable and you can’t directly update them by changing a property, instead you have to work with the widget’s state. This is where the concept of Stateful vs Stateless widgets comes from. A StatelessWidget is just what it sounds like— a widget with no state information. StatelessWidgets are useful when the part of the user interface you are describing doesn’t depend on anything other than the configuration information in the object. For example, in Xamarin.Forms, this is similar to placing an Image with your logo. The logo is not going to change during runtime, so use a StatelessWidget in Flutter.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-9
If you want to dynamically change the UI based on data received after making an HTTP call or a user interaction, then you have to work with StatefulWidget and tell the Flutter framework that the widget’s State has been updated, so it can update that widget. The important thing to note here is at the core both stateless and stateful widgets behave the same. They rebuild every frame, the difference is the StatefulWidget has a State object that stores state data across frames and restores it. If you are in doubt, then always remember this rule: if a widget changes (because of user interactions, for example) it’s stateful. However, if a widget reacts to change, the containing parent widget can still be stateless if it doesn’t itself react to change. The following example shows how to use a StatelessWidget. A common StatelessWidget is the Text widget. If you look at the implementation of the Text widget you’ll find it subclasses StatelessWidget.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-10
As you can see, the Text widget has no state information associated with it, it renders what is passed in its constructors and nothing more. But, what if you want to make “I Like Flutter” change dynamically, for example, when clicking a FloatingActionButton? To achieve this, wrap the Text widget in a StatefulWidget and update it when the user clicks the button, as shown in the following example: How do I lay out my widgets? What is the equivalent of an XAML file? In Xamarin.Forms, most developers write layouts in XAML, though sometimes in C#. In Flutter, you write your layouts with a widget tree in code. The following example shows how to display a simple widget with padding: You can view the layouts that Flutter has to offer in the widget catalog. How do I add or remove an Element from my layout?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-11
How do I add or remove an Element from my layout? In Xamarin.Forms, you had to remove or add an Element in code. This involved either setting the Content property or calling Add() or Remove() if it was a list. In Flutter, because widgets are immutable there is no direct equivalent. Instead, you can pass a function to the parent that returns a widget, and control that child’s creation with a boolean flag. The following example shows how to toggle between two widgets when the user clicks the FloatingActionButton: How do I animate a widget? In Xamarin.Forms, you create simple animations using ViewExtensions that include methods such as FadeTo and TranslateTo. You would use these methods on a view to perform the required animations. <Image Source= "{Binding MyImage}" x:Name= "myImage" />
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-12
x:Name= "myImage" /> Then in code behind, or a behavior, this would fade in the image, over a 1-second period. myImage FadeTo 1000 ); In Flutter, you animate widgets using the animation library by wrapping widgets inside an animated widget. Use an AnimationController, which is an Animation<double> that can pause, seek, stop and reverse the animation. It requires a Ticker that signals when vsync happens, and produces a linear interpolation between 0 and 1 on each frame while it’s running. You then create one or moreAnimations and attach them to the controller.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-13
For example, you might use CurvedAnimation to implement an animation along an interpolated curve. In this sense, the controller is the “master” source of the animation progress and the CurvedAnimation computes the curve that replaces the controller’s default linear motion. Like widgets, animations in Flutter work with composition. When building the widget tree, you assign the Animation to an animated property of a widget, such as the opacity of a FadeTransition, and tell the controller to start the animation. The following example shows how to write a FadeTransition that fades the widget into a logo when you press the FloatingActionButton: For more information, see Animation & Motion widgets, the Animations tutorial, and the Animations overview. How do I draw/paint on the screen?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-14
How do I draw/paint on the screen? Xamarin.Forms never had a built-in way to draw directly on the screen. Many would use SkiaSharp, if they needed a custom image drawn. In Flutter, you have direct access to the Skia Canvas and can easily draw on screen. Flutter has two classes that help you draw to the canvas: CustomPaint and CustomPainter, the latter of which implements your algorithm to draw to the canvas. To learn how to implement a signature painter in Flutter, see Collin’s answer on StackOverflow. Where is the widget’s opacity? On Xamarin.Forms, all VisualElements have an Opacity. In Flutter, you need to wrap a widget in an Opacity widget to accomplish this. How do I build custom widgets? In Xamarin.Forms, you typically subclass VisualElement, or use a pre-existing VisualElement, to override and implement methods that achieve the desired behavior.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-15
In Flutter, build a custom widget by composing smaller widgets (instead of extending them). It is somewhat similar to implementing a custom control based off a Grid with numerous VisualElements added in, while extending with custom logic. For example, how do you build a CustomButton that takes a label in the constructor? Create a CustomButton that composes a ElevatedButton with a label, rather than by extending ElevatedButton: Then use CustomButton, just as you’d use any other Flutter widget: Navigation How do I navigate between pages? In Xamarin.Forms, the NavigationPage class provides a hierarchical navigation experience where the user is able to navigate through pages, forwards and backwards. widget that manages routes.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-16
widget that manages routes. A route roughly maps to a Page. The navigator works in a similar way to the Xamarin.Forms NavigationPage, in that it can push() and pop() routes depending on whether you want to navigate to, or back from, a view. To navigate between pages, you have a couple options: Specify a Map of route names. (MaterialApp) Directly navigate to a route. (WidgetsApp) The following example builds a Map. Navigate to a route by pushing its name to the Navigator. The Navigator is a stack that manages your app’s routes. Pushing a route to the stack moves to that route. Popping a route from the stack, returns to the previous route. This is done by awaiting on the Future returned by push(). async/await is very similar to the .NET implementation and is explained in more detail in Async UI.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-17
For example, to start a location route that lets the user select their location, you might do the following: And then, inside your ‘location’ route, once the user has selected their location, pop the stack with the result: How do I navigate to another app? In Xamarin.Forms, to send the user to another application, you use a specific URI scheme, using Device.OpenUrl("mailto://"). To implement this functionality in Flutter, create a native platform integration, or use an existing plugin, such asurl_launcher, available with many other packages on pub.dev. Async UI What is the equivalent of Device.BeginOnMainThread() in Flutter?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-18
What is the equivalent of Device.BeginOnMainThread() in Flutter? Dart has a single-threaded execution model, with support for Isolates (a way to run Dart codes on another thread), an event loop, and asynchronous programming. Unless you spawn an Isolate, your Dart code runs in the main UI thread and is driven by an event loop. Dart’s single-threaded model doesn’t mean you need to run everything as a blocking operation that causes the UI to freeze. Much like Xamarin.Forms, you need to keep the UI thread free. You would use async/await to perform tasks, where you must wait for the response. In Flutter, use the asynchronous facilities that the Dart language provides, also named async/await, to perform asynchronous work. This is very similar to C# and should be very easy to use for any Xamarin.Forms developer.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-19
For example, you can run network code without causing the UI to hang by using async/await and letting Dart do the heavy lifting: Once the awaited network call is done, update the UI by calling setState(), which triggers a rebuild of the widget subtree and updates the data. The following example loads data asynchronously and displays it in a ListView: Refer to the next section for more information on doing work in the background, and how Flutter differs from Android. How do you move work to a background thread? Since Flutter is single threaded and runs an event loop, you don’t have to worry about thread management or spawning background threads. This is very similar to Xamarin.Forms. If you’re doing I/O-bound work, such as disk access or a network call, then you can safely use async/await and you’re all set.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-20
If, on the other hand, you need to do computationally intensive work that keeps the CPU busy, you want to move it to an Isolate to avoid blocking the event loop, like you would keep any sort of work out of the main thread. This is similar to when you move things to a different thread via Task.Run() in Xamarin.Forms. For I/O-bound work, declare the function as an async function, and await on long-running tasks inside the function: This is how you would typically do network or database calls, which are both I/O operations. However, there are times when you might be processing a large amount of data and your UI hangs. In Flutter, use Isolates to take advantage of multiple CPU cores to do long-running or computationally intensive tasks.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-21
Isolates are separate execution threads that do not share any memory with the main execution memory heap. This is a difference between Task.Run(). This means you can’t access variables from the main thread, or update your UI by calling setState(). The following example shows, in a simple isolate, how to share data back to the main thread to update the UI. Here, dataLoader() is the Isolate that runs in its own separate execution thread. In the isolate, you can perform more CPU intensive processing (parsing a big JSON, for example), or perform computationally intensive math, such as encryption or signal processing. You can run the full example below: How do I make network requests? In Xamarin.Forms you would use HttpClient. Making a network call in Flutter is easy when you use the popular http package. This abstracts away a lot of the networking that you might normally implement yourself, making it simple to make network calls.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-22
To use the http package, add it to your dependencies in pubspec.yaml: dependencies http ^0.13.4 To make a network request, call await on the async function http.get(): How do I show the progress for a long-running task? In Xamarin.Forms you would typically create a loading indicator, either directly in XAML or through a 3rd party plugin such as AcrDialogs. In Flutter, use a ProgressIndicator widget. Show the progress programmatically by controlling when it’s rendered through a boolean flag. Tell Flutter to update its state before your long-running task starts, and hide it after it ends. In the example below, the build function is separated into three different functions. If showLoadingDialog is true (when widgets.length == 0), then render the ProgressIndicator. Otherwise, render the ListView with the data returned from a network call.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-23
Project structure & resources Where do I store my image files? Xamarin.Forms has no platform independent way of storing images, you had to place images in the iOS xcasset folder, or on Android in the various drawable folders. While Android and iOS treat resources and assets as distinct items, Flutter apps have only assets. All resources that would live in the Resources/drawable-* folders on Android, are placed in an assets’ folder for Flutter. Flutter follows a simple density-based format like iOS. Assets might be 1.0x, 2.0x, 3.0x, or any other multiplier. Flutter doesn’t have dps but there are logical pixels, which are basically the same as device-independent pixels. The so-called devicePixelRatio expresses the ratio of physical pixels in a single logical pixel. The equivalent to Android’s density buckets are: ldpi 0.75x
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-24
ldpi 0.75x mdpi 1.0x hdpi 1.5x xhdpi 2.0x xxhdpi 3.0x xxxhdpi 4.0x Assets are located in any arbitrary folder— Flutter has no predefined folder structure. You declare the assets (with location) in the pubspec.yaml file, and Flutter picks them up. To add a new image asset called my_icon.png to our Flutter project, for example, and deciding that it should live in a folder we arbitrarily called images, you would put the base image (1.0x) in the images folder, and all the other variants in sub-folders called with the appropriate ratio multiplier:
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-25
Next, you’ll need to declare these images in your pubspec.yaml file: assets images/my_icon.jpeg You can directly access your images in an Image.asset widget: or using AssetImage: More detailed information can be found in Adding assets and images. Where do I store strings? How do I handle localization? Unlike .NET which has resx files, Flutter doesn’t currently have a dedicated system for handling strings. At the moment, the best practice is to declare your copy text in a class as static fields and access them from there. For example: You can access your strings as such: By default, Flutter only supports US English for its strings. If you need to add support for other languages, include the flutter_localizations package. You might also need to add Dart’s intl package to use i10n machinery, such as date/time formatting. dependencies
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-26
dependencies flutter_localizations sdk flutter intl ^0.17.0' To use the flutter_localizations package, specify the localizationsDelegates and supportedLocales on the app widget: The delegates contain the actual localized values, while the supportedLocales defines which locales the app supports. The above example uses a MaterialApp, so it has both a GlobalWidgetsLocalizations for the base widgets localized values, and a MaterialWidgetsLocalizations for the Material widgets localizations. If you use WidgetsApp for your app, you don’t need the latter. Note that these two delegates contain “default” values, but you’ll need to provide one or more delegates for your own app’s localizable copy, if you want those to be localized too. Localizations widget for you, with the delegates you specify. The current locale for the device is always accessible from the
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-27
Window.locale. To access localized resources, use the Localizations.of() method to access a specific localizations class that is provided by a given delegate. Use the intl_translation package to extract translatable copy to arb files for translating, and importing them back into the app for using them with intl. For further details on internationalization and localization in Flutter, see the internationalization guide, which has sample code with and without the intl package. Where is my project file? In Xamarin.Forms you will have a csproj file. The closest equivalent in Flutter is pubspec.yaml, which contains package dependencies and various project details. Similar to .NET Standard, files within the same directory are considered part of the project. What is the equivalent of Nuget? How do I add dependencies?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-28
What is the equivalent of Nuget? How do I add dependencies? In the .NET ecosystem, native Xamarin projects and Xamarin.Forms projects had access to Nuget and the built-in package management system. Flutter apps contain a native Android app, native iOS app and Flutter app. In Android, you add dependencies by adding to your Gradle build script. In iOS, you add dependencies by adding to your Podfile. Flutter uses Dart’s own build system, and the Pub package manager. The tools delegate the building of the native Android and iOS wrapper apps to the respective build systems. In general, use pubspec.yaml to declare external dependencies to use in Flutter. A good place to find Flutter packages is on pub.dev. Application lifecycle How do I listen to application lifecycle events? The observable lifecycle events are: The application is in an inactive state and is not receiving user input. This event is iOS only.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-29
The application is not currently visible to the user, is not responding to user input, but is running in the background. The application is visible and responding to user input. The application is suspended momentarily. This event is Android only. For more details on the meaning of these states, see the AppLifecycleStatus documentation. Layouts What is the equivalent of a StackLayout? In Xamarin.Forms you can create a StackLayout with an Orientation of horizontal or vertical. Flutter has a similar approach, however you would use the Row or Column widgets. If you notice the two code samples are identical except the Row and Column widget. The children are the same and this feature can be exploited to develop rich layouts that can change overtime with the same children. What is the equivalent of a Grid?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-30
What is the equivalent of a Grid? The closest equivalent of a Grid would be a GridView. This is much more powerful than what you are used to in Xamarin.Forms. A GridView provides automatic scrolling when the content exceeds its viewable space. You might have used a Grid in Xamarin.Forms to implement widgets that overlay other widgets. In Flutter, you accomplish this with the Stack widget. This sample creates two icons that overlap each other. What is the equivalent of a ScrollView? In Xamarin.Forms, a ScrollView wraps around a VisualElement, and if the content is larger than the device screen, it scrolls. In Flutter, the closest match is the SingleChildScrollView widget. You simply fill the Widget with the content that you want to be scrollable.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-31
If you have many items you want to wrap in a scroll, even of different Widget types, you might want to use a ListView. This might seem like overkill, but in Flutter this is far more optimized and less intensive than a Xamarin.Forms ListView, which is backing on to platform specific controls. How do I handle landscape transitions in Flutter? Landscape transitions can be handled automatically by setting the configChanges property in the AndroidManifest.xml: <activity android:configChanges= "orientation|screenSize" /> Gesture detection and touch event handling How do I add GestureRecognizers to a widget in Flutter? In Xamarin.Forms, Elements might contain a click event you can attach to. Many elements also contain a Command that is tied to this event. Alternatively you would use the TapGestureRecognizer. In Flutter there are two very similar ways:
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-32
If the widget supports event detection, pass a function to it and handle it in the function. For example, the ElevatedButton has an onPressed parameter: @override Widget build(BuildContext context) { return ElevatedButton( onPressed: () { developer.log('click'); }, child: const Text('Button'), ); } If the widget doesn’t support event detection, wrap the widget in a GestureDetector and pass a function to the onTap parameter. class SampleApp extends StatelessWidget { const SampleApp({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: GestureDetector( onTap: () { developer.log('tap'); }, child: const FlutterLogo(size: 200.0), ), ), ); } }
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-33
How do I handle other gestures on widgets? In Flutter, using the GestureDetector, you can listen to a wide range of Gestures such as: Tap A pointer that might cause a tap has contacted the screen at a particular location. A pointer that triggers a tap has stopped contacting the screen at a particular location. A tap has occurred. The pointer that previously triggered the onTapDown won’t cause a tap. Double tap The user tapped the screen at the same location twice in quick succession. Long press A pointer has remained in contact with the screen at the same location for a long period of time. Vertical drag A pointer has contacted the screen and might begin to move vertically. A pointer in contact with the screen has moved further in the vertical direction.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-34
A pointer in contact with the screen has moved further in the vertical direction. A pointer that was previously in contact with the screen and moving vertically is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen. Horizontal drag A pointer has contacted the screen and might begin to move horizontally. A pointer in contact with the screen has moved further in the horizontal direction. A pointer that was previously in contact with the screen and moving horizontally is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen. The following example shows a GestureDetector that rotates the Flutter logo on a double tap: Listviews and adapters What is the equivalent to a ListView in Flutter? The equivalent to a ListView in Flutter is … a ListView!
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-35
The equivalent to a ListView in Flutter is … a ListView! Due to Flutter’s immutable widget pattern, you pass a list of widgets to your ListView, and Flutter takes care of making sure that scrolling is fast and smooth. How do I know which list item has been clicked? In Xamarin.Forms, the ListView has an ItemTapped method to find out which item was clicked. There are many other techniques you might have used such as checking when SelectedItem or EventToCommand behaviors change. In Flutter, use the touch handling provided by the passed-in widgets. How do I update a ListView dynamically? In Xamarin.Forms, if you bound the ItemsSource property to an ObservableCollection, you would just update the list in your ViewModel. Alternatively, you could assign a new List to the ItemSource property.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-36
In Flutter, things work a little differently. If you update the list of widgets inside a setState() method, you would quickly see that your data did not change visually. This is because when setState() is called, the Flutter rendering engine looks at the widget tree to see if anything has changed. When it gets to your ListView, it performs a == check, and determines that the two ListViews are the same. Nothing has changed, so no update is required. For a simple way to update your ListView, create a new List inside of setState(), and copy the data from the old list to the new list. While this approach is simple, it is not recommended for large data sets, as shown in the next example. The recommended, efficient, and effective way to build a list uses a ListView.Builder. This method is great when you have a dynamic list or a list with very large amounts of data. This is essentially the equivalent of RecyclerView on Android, which automatically recycles list elements for you:
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-37
Instead of creating a ListView, create a ListView.builder that takes two key parameters: the initial length of the list, and an item builder function. The item builder function is similar to the getView function in an Android adapter; it takes a position, and returns the row you want rendered at that position. Finally, but most importantly, notice that the onTap() function doesn’t recreate the list anymore, but instead adds to it. For more information, see Your first Flutter app codelab. Working with text How do I set custom fonts on my text widgets? In Xamarin.Forms, you would have to add a custom font in each native project. Then, in your Element you would assign this font name to the FontFamily attribute using filename#fontname and just fontname for iOS. In Flutter, place the font file in a folder and reference it in the pubspec.yaml file, similar to how you import images. fonts
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-38
fonts family MyCustomFont fonts asset fonts/MyCustomFont.ttf style italic Then assign the font to your Text widget: How do I style my text widgets? Along with fonts, you can customize other styling elements on a Text widget. The style parameter of a Text widget takes a TextStyle object, where you can customize many parameters, such as: color decoration decorationColor decorationStyle fontFamily fontSize fontStyle fontWeight hashCode height inherit letterSpacing textBaseline wordSpacing Form input How do I retrieve user input?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-39
Form input How do I retrieve user input? Xamarin.Forms elements allow you to directly query the element to determine the state of its properties, or whether it’s bound to a property in a ViewModel. Retrieving information in Flutter is handled by specialized widgets and is different from how you are used to. If you have a TextFieldor a TextFormField, you can supply a TextEditingController to retrieve user input: You can find more information and the full code listing in Retrieve the value of a text field, from the Flutter cookbook. What is the equivalent of a Placeholder on an Entry? In Xamarin.Forms, some Elements support a Placeholder property that you can assign a value to. For example: <Entry Placeholder= "This is a hint"
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-40
Placeholder= "This is a hint" In Flutter, you can easily show a “hint” or a placeholder text for your input by adding an InputDecoration object to the decoration constructor parameter for the text widget. How do I show validation errors? With Xamarin.Forms, if you wished to provide a visual hint of a validation error, you would need to create new properties and VisualElements surrounding the Elements that had validation errors. In Flutter, you pass through an InputDecoration object to the decoration constructor for the text widget. However, you don’t want to start off by showing an error. Instead, when the user has entered invalid data, update the state, and pass a new InputDecoration object. Flutter plugins Interacting with hardware, third party services, and the platform How do I interact with the platform, and with platform native code?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-41
How do I interact with the platform, and with platform native code? Flutter doesn’t run code directly on the underlying platform; rather, the Dart code that makes up a Flutter app is run natively on the device, “sidestepping” the SDK provided by the platform. That means, for example, when you perform a network request in Dart, it runs directly in the Dart context. You don’t use the Android or iOS APIs you normally take advantage of when writing native apps. Your Flutter app is still hosted in a native app’s ViewController or Activity as a view, but you don’t have direct access to this, or the native framework.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-42
This doesn’t mean Flutter apps can’t interact with those native APIs, or with any native code you have. Flutter provides platform channels that communicate and exchange data with the ViewController or Activity that hosts your Flutter view. Platform channels are essentially an asynchronous messaging mechanism that bridges the Dart code with the host ViewController or Activity and the iOS or Android framework it runs on. You can use platform channels to execute a method on the native side, or to retrieve some data from the device’s sensors, for example. In addition to directly using platform channels, you can use a variety of pre-made plugins that encapsulate the native and Dart code for a specific goal. For example, you can use a plugin to access the camera roll and the device camera directly from Flutter, without having to write your own integration. Plugins are found on pub.dev, Dart and Flutter’s open source package repository. Some packages might support native integrations on iOS, or Android, or both.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-43
If you can’t find a plugin on pub.dev that fits your needs, you can write your own, and publish it on pub.dev. How do I access the GPS sensor? Use the geolocator community plugin. How do I access the camera? The camera plugin is popular for accessing the camera. How do I log in with Facebook? To log in with Facebook, use the flutter_facebook_login community plugin. How do I use Firebase features? Most Firebase functions are covered by first party plugins. These plugins are first-party integrations, maintained by the Flutter team: firebase_admob for Firebase AdMob firebase_analytics for Firebase Analytics firebase_auth for Firebase Auth firebase_database for Firebase RTDB firebase_storage for Firebase Cloud Storage firebase_messaging for Firebase Messaging (FCM)
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-44
firebase_messaging for Firebase Messaging (FCM) flutter_firebase_ui for quick Firebase Auth integrations (Facebook, Google, Twitter and email) cloud_firestore for Firebase Cloud Firestore You can also find some third-party Firebase plugins on pub.dev that cover areas not directly covered by the first-party plugins. How do I build my own custom native integrations? If there is platform-specific functionality that Flutter or its community plugins are missing, you can build your own following the developing packages and plugins page. Flutter’s plugin architecture, in a nutshell, is much like using an Event bus in Android: you fire off a message and let the receiver process and emit a result back to you. In this case, the receiver is code running on the native side on Android or iOS. Themes (Styles) How do I theme my app?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-45
Themes (Styles) How do I theme my app? Flutter comes with a beautiful, built-in implementation of Material Design, which handles much of the styling and theming needs that you would typically do. Xamarin.Forms does have a global ResourceDictionary where you can share styles across your app. Alternatively, there is Theme support currently in preview. In Flutter, you declare themes in the top level widget. To take full advantage of Material Components in your app, you can declare a top level widget MaterialApp as the entry point to your application. MaterialApp is a convenience widget that wraps a number of widgets that are commonly required for applications implementing Material Design. It builds upon a WidgetsApp by adding Material-specific functionality. You can also use a WidgetsApp as your app widget, which provides some of the same functionality, but is not as rich as MaterialApp.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-46
To customize the colors and styles of any child components, pass a ThemeData object to the MaterialApp widget. For example, in the following code, the primary swatch is set to blue and text selection color is red. Databases and local storage How do I access shared preferences or UserDefaults? Xamarin.Forms developers will likely be familiar with the Xam.Plugins.Settings plugin. In Flutter, access equivalent functionality using the shared_preferences plugin. This plugin wraps the functionality of both UserDefaults and the Android equivalent, SharedPreferences. How do I access SQLite in Flutter? In Xamarin.Forms most applications would use the sqlite-net-pcl plugin to access SQLite databases. In Flutter, access this functionality using the sqflite plugin. Debugging What tools can I use to debug my app in Flutter?
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
2916fac8cda4-47
What tools can I use to debug my app in Flutter? Use the DevTools suite for debugging Flutter or Dart apps. DevTools includes support for profiling, examining the heap, inspecting the widget tree, logging diagnostics, debugging, observing executed lines of code, debugging memory leaks and memory fragmentation. For more information, see the DevTools documentation. Notifications How do I set up push notifications? In Android, you use Firebase Cloud Messaging to setup push notifications for your app. In Flutter, access this functionality using the firebase_messaging plugin. For more information on using the Firebase Cloud Messaging API, see the firebase_messaging plugin documentation.
https://docs.flutter.dev/get-started/flutter-for/xamarin-forms-devs/index.html
d1ed87a820df-0
Get started Get started
https://docs.flutter.dev/get-started/index.html
65dd0840706f-0
Set up an editor ChromeOS install Get started Install ChromeOS System requirements Get the Flutter SDK Run flutter doctor Configuring web app support Configuring Android app support Install Android Studio Deploy to your Chromebook Set up your Android device Next step System requirements To install and run Flutter on a Chromebook, your machine must have Linux enabled from the Developers tab of Settings. The amount of disk space required varies depending on which target platforms you enable. We recommend that you increase the disk size for the Linux environment from the default of 10GB to 32GB or larger, to accommodate Android Studio and other tooling. Get the Flutter SDK Install the core development tools needed for Flutter:
https://docs.flutter.dev/get-started/install/chromeos/index.html
65dd0840706f-1
Install the core development tools needed for Flutter: $ sudo apt install clang cmake ninja-build pkg-config libgtk-3-dev This downloads the compiler toolchain needed to compile apps for ChromeOS. Download Flutter from the Flutter repo on GitHub with the following command in your home directory: $ git clone https://github.com/flutter/flutter.git -b stable Add the flutter tool to your path: $ echo PATH="$PATH:`pwd`/flutter/bin" >> ~/.profile $ source ~/.profile You are now ready to run Flutter commands! Run flutter doctor Run the following command to see if there are any dependencies you need to install to complete the setup (for verbose output, add the -v flag): flutter doctor
https://docs.flutter.dev/get-started/install/chromeos/index.html
65dd0840706f-2
flutter doctor This command checks your environment and displays a report to the terminal window. The Dart SDK is bundled with Flutter; it is not necessary to install Dart separately. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text). For example: The following sections describe how to perform these tasks and finish the setup process. Once you have installed any missing dependencies, run the flutter doctor command again to verify that you’ve set everything up correctly. Warning: The Flutter tool may occasionally download resources from Google servers. By downloading or using the Flutter SDK you agree to the Google Terms of Service.
https://docs.flutter.dev/get-started/install/chromeos/index.html
65dd0840706f-3
For example, when installed from GitHub (as opposed to from a prepackaged archive), the Flutter tool will download the Dart SDK from Google servers immediately when first run, as it is used to execute the flutter tool itself. This will also occur when Flutter is upgraded (e.g. by running the flutter upgrade command). The flutter tool uses Google Analytics to report feature usage statistics and send crash reports. This data is used to help improve Flutter tools over time. Flutter tool analytics are not sent on the very first run. To disable reporting, run flutter config --no-analytics. To display the current setting, use flutter config. If you opt out of analytics, an opt-out event is sent, and then no further information is sent by the Flutter tool. Dart tools may also send usage metrics and crash reports to Google. To control the submission of these metrics, use the following options on the dart tool:
https://docs.flutter.dev/get-started/install/chromeos/index.html
65dd0840706f-4
--enable-analytics: Enables anonymous analytics. --disable-analytics: Disables anonymous analytics. The Google Privacy Policy describes how data is handled by these services. Configuring web app support On ChromeOS, you do development work in a Linux container. However, the Chrome browser itself is part of the parent ChromeOS operating system, and Flutter doesn’t have a means to call it with the required parameters. Track this issue at Issue 121462: Improve the web debugging experience on Chromebooks. Instead, the best approach is to manually install a second copy of Chrome in the Linux container. You can do that with the following steps: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo apt install ./google-chrome-stable_current_amd64.deb Configuring Android app support
https://docs.flutter.dev/get-started/install/chromeos/index.html