id
stringlengths
14
17
text
stringlengths
23
1.11k
source
stringlengths
35
114
99a6832fcc4d-1
Integration tests are written using the integration_test package, provided by the SDK. In this recipe, learn how to test a counter app. It demonstrates how to setup integration tests, how to verify specific text is displayed by the app, how to tap specific widgets, and how to run integration tests. This recipe uses the following steps: Create an app to test. Add the integration_test dependency. Create the test files. Write the integration test. Run the integration test. 1. Create an app to test First, create an app for testing. In this example, test the counter app produced by the flutter create command. This app allows a user to tap on a button to increase a counter. 2. Add the integration_test dependency
https://docs.flutter.dev/cookbook/testing/integration/introduction/index.html
99a6832fcc4d-2
2. Add the integration_test dependency Next, use the integration_test and flutter_test packages to write integration tests. Add these dependencies to the dev_dependencies section of the app’s pubspec.yaml file, specifying the Flutter SDK as the location of the package. dev_dependencies integration_test sdk flutter flutter_test sdk flutter 3. Create the test files Create a new directory, integration_test, with an empty app_test.dart file: 4. Write the integration test Now you can write tests. This involves three steps: Initialize IntegrationTestWidgetsFlutterBinding, a singleton service that executes tests on a physical device. Interact and tests widgets using the WidgetTester class. Test the important scenarios. 5. Run the integration test
https://docs.flutter.dev/cookbook/testing/integration/introduction/index.html
99a6832fcc4d-3
Test the important scenarios. 5. Run the integration test The process of running the integration tests varies depending on the platform you are testing against. You can test against a mobile platform or the web. 5a. Mobile To test on a real iOS / Android device, first connect the device and run the following command from the root of the project: flutter test integration_test/app_test.dart Or, you can specify the directory to run all integration tests: flutter test integration_test This command runs the app and integration tests on the target device. For more information, see the Integration testing page. 5b. Web To get started testing in a web browser, Download ChromeDriver. Next, create a new directory named test_driver containing a new file named integration_test.dart: Launch chromedriver as follows:
https://docs.flutter.dev/cookbook/testing/integration/introduction/index.html
99a6832fcc4d-4
Launch chromedriver as follows: chromedriver --port=4444 From the root of the project, run the following command: flutter drive \ --driver=test_driver/integration_test.dart \ --target=integration_test/app_test.dart \ -d chrome For a headless testing experience, you can also run flutter drive with web-server as the target device identifier as follows: flutter drive \ --driver=test_driver/integration_test.dart \ --target=integration_test/app_test.dart \ -d web-server Take a picture using the camera Performance profiling
https://docs.flutter.dev/cookbook/testing/integration/introduction/index.html
c4c5e06d254c-0
An introduction to integration testing An introduction to unit testing Performance profiling Cookbook Testing Integration Performance profiling 1. Write a test that scrolls through a list of items 2. Record the performance of the app 3. Save the results to disk 4. Run the test 5. Review the results Summary example Complete example When it comes to mobile apps, performance is critical to user experience. Users expect apps to have smooth scrolling and meaningful animations free of stuttering or skipped frames, known as “jank.” How to ensure that your app is free of jank on a wide variety of devices?
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-1
There are two options: first, manually test the app on different devices. While that approach might work for a smaller app, it becomes more cumbersome as an app grows in size. Alternatively, run an integration test that performs a specific task and records a performance timeline. Then, examine the results to determine whether a specific section of the app needs to be improved. In this recipe, learn how to write a test that records a performance timeline while performing a specific task and saves a summary of the results to a local file. This recipe uses the following steps: Write a test that scrolls through a list of items. Record the performance of the app. Save the results to disk. Run the test. Review the results. 1. Write a test that scrolls through a list of items
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-2
1. Write a test that scrolls through a list of items In this recipe, record the performance of an app as it scrolls through a list of items. To focus on performance profiling, this recipe builds on the Scrolling recipe in widget tests. Follow the instructions in that recipe to create an app and write a test to verify that everything works as expected. 2. Record the performance of the app Next, record the performance of the app as it scrolls through the list. Perform this task using the traceAction() method provided by the IntegrationTestWidgetsFlutterBinding class. This method runs the provided function and records a Timeline with detailed information about the performance of the app. This example provides a function that scrolls through the list of items, ensuring that a specific item is displayed. When the function completes, the traceAction() creates a report data Map that contains the Timeline. 3. Save the results to disk
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-3
3. Save the results to disk Now that you’ve captured a performance timeline, you need a way to review it. The Timeline object provides detailed information about all of the events that took place, but it doesn’t provide a convenient way to review the results. Therefore, convert the Timeline into a TimelineSummary. The TimelineSummary can perform two tasks that make it easier to review the results: Writing a json document on disk that summarizes the data contained within the Timeline. This summary includes information about the number of skipped frames, slowest build times, and more. Saving the complete Timeline as a json file on disk. This file can be opened with the Chrome browser’s tracing tools found at chrome://tracing. To capture the results, create a file named perf_driver.dart in the test_driver folder and add the following code:
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-4
The integrationDriver function has a responseDataCallback which you can customize. By default, it writes the results to the integration_response_data.json file, but you can customize it to generate a summary like in this example. 4. Run the test After configuring the test to capture a performance Timeline and save a summary of the results to disk, run the test with the following command: The --profile option means to compile the app for the “profile mode” rather than the “debug mode”, so that the benchmark result is closer to what will be experienced by end users. Note: Run the command with --no-dds when running on a mobile device or emulator. This option disables the Dart Development Service (DDS), which won’t be accessible from your computer. 5. Review the results After the test completes successfully, the build directory at the root of the project contains two files:
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-5
scrolling_summary.timeline_summary.json contains the summary. Open the file with any text editor to review the information contained within. With a more advanced setup, you could save a summary every time the test runs and create a graph of the results. scrolling_timeline.timeline.json contains the complete timeline data. Open the file using the Chrome browser’s tracing tools found at chrome://tracing. The tracing tools provide a convenient interface for inspecting the timeline data to discover the source of a performance issue. Summary example "average_frame_build_time_millis" 4.2592592592592595 "worst_frame_build_time_millis" 21.0 "missed_frame_build_budget_count" "average_frame_rasterizer_time_millis"
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-6
"average_frame_rasterizer_time_millis" 5.518518518518518 "worst_frame_rasterizer_time_millis" 51.0 "missed_frame_rasterizer_budget_count" 10 "frame_count" 54 "frame_build_times" 6874 5019 3638 ], "frame_rasterizer_times" 51955 8468 3129 Complete example integration_test/scrolling_test.dart test_driver/perf_driver.dart
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
c4c5e06d254c-7
test_driver/perf_driver.dart An introduction to integration testing An introduction to unit testing
https://docs.flutter.dev/cookbook/testing/integration/profiling/index.html
3895f94c088a-0
Unit Cookbook Testing Unit An introduction to unit testing Mock dependencies using Mockito
https://docs.flutter.dev/cookbook/testing/unit/index.html
8a0f5a9b4f7b-0
Performance profiling Mock dependencies using Mockito An introduction to unit testing Cookbook Testing Unit Introduction 1. Add the test dependency 2. Create a test file 3. Create a class to test 4. Write a test for our class 5. Combine multiple tests in a group 6. Run the tests Run tests using IntelliJ or VSCode Run tests in a terminal How can you ensure that your app continues to work as you add more features or change existing functionality? By writing tests. Unit tests are handy for verifying the behavior of a single function, method, or class. The test package provides the core framework for writing unit tests, and the flutter_test package provides additional utilities for testing widgets.
https://docs.flutter.dev/cookbook/testing/unit/introduction/index.html
8a0f5a9b4f7b-1
This recipe demonstrates the core features provided by the test package using the following steps: Add the test or flutter_test dependency. Create a test file. Create a class to test. Write a test for our class. Combine multiple tests in a group. Run the tests. For more information about the test package, see the test package documentation. 1. Add the test dependency The test package provides the core functionality for writing tests in Dart. This is the best approach when writing packages consumed by web, server, and Flutter apps. dev_dependencies test <latest_version> 2. Create a test file In this example, create two files: counter.dart and counter_test.dart.
https://docs.flutter.dev/cookbook/testing/unit/introduction/index.html
8a0f5a9b4f7b-2
In this example, create two files: counter.dart and counter_test.dart. The counter.dart file contains a class that you want to test and resides in the lib folder. The counter_test.dart file contains the tests themselves and lives inside the test folder. In general, test files should reside inside a test folder located at the root of your Flutter application or package. Test files should always end with _test.dart, this is the convention used by the test runner when searching for tests. When you’re finished, the folder structure should look like this: 3. Create a class to test Next, you need a “unit” to test. Remember: “unit” is another name for a function, method, or class. For this example, create a Counter class inside the lib/counter.dart file. It is responsible for incrementing and decrementing a value starting at 0.
https://docs.flutter.dev/cookbook/testing/unit/introduction/index.html
8a0f5a9b4f7b-3
Note: For simplicity, this tutorial does not follow the “Test Driven Development” approach. If you’re more comfortable with that style of development, you can always go that route. 4. Write a test for our class Inside the counter_test.dart file, write the first unit test. Tests are defined using the top-level test function, and you can check if the results are correct by using the top-level expect function. Both of these functions come from the test package. 5. Combine multiple tests in a group If you have several tests that are related to one another, combine them using the group function provided by the test package. 6. Run the tests Now that you have a Counter class with tests in place, you can run the tests. Run tests using IntelliJ or VSCode
https://docs.flutter.dev/cookbook/testing/unit/introduction/index.html
8a0f5a9b4f7b-4
Run tests using IntelliJ or VSCode The Flutter plugins for IntelliJ and VSCode support running tests. This is often the best option while writing tests because it provides the fastest feedback loop as well as the ability to set breakpoints. IntelliJ Open the counter_test.dart file Select the Run menu Click the Run 'tests in counter_test.dart' option Alternatively, use the appropriate keyboard shortcut for your platform. VSCode Open the counter_test.dart file Select the Run menu Click the Start Debugging option Alternatively, use the appropriate keyboard shortcut for your platform. Run tests in a terminal You can also use a terminal to run the tests by executing the following command from the root of the project: For more options regarding unit tests, you can execute this command: Performance profiling Mock dependencies using Mockito
https://docs.flutter.dev/cookbook/testing/unit/introduction/index.html
64b454328c00-0
An introduction to unit testing An introduction to widget testing Mock dependencies using Mockito Cookbook Testing Unit Mocking 1. Add the package dependencies 2. Create a function to test 3. Create a test file with a mock http.Client 4. Write a test for each condition 5. Run the tests Complete example Summary Sometimes, unit tests might depend on classes that fetch data from live web services or databases. This is inconvenient for a few reasons: Calling live services or databases slows down test execution. A passing test might start failing if a web service or database returns unexpected results. This is known as a “flaky test.” It is difficult to test all possible success and failure scenarios by using a live web service or database.
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-1
Therefore, rather than relying on a live web service or database, you can “mock” these dependencies. Mocks allow emulating a live web service or database and return specific results depending on the situation. Generally speaking, you can mock dependencies by creating an alternative implementation of a class. Write these alternative implementations by hand or make use of the Mockito package as a shortcut. This recipe demonstrates the basics of mocking with the Mockito package using the following steps: Add the package dependencies. Create a function to test. Create a test file with a mock http.Client. Write a test for each condition. Run the tests. For more information, see the Mockito package documentation. 1. Add the package dependencies To use the mockito package, add it to the pubspec.yaml file along with the flutter_test dependency in the dev_dependencies section.
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-2
This example also uses the http package, so define that dependency in the dependencies section. mockito: 5.0.0 supports Dart’s null safety thanks to code generation. To run the required code generation, add the build_runner dependency in the dev_dependencies section. dependencies http <newest_version> dev_dependencies flutter_test sdk flutter mockito <newest_version> build_runner <newest_version> 2. Create a function to test In this example, unit test the fetchAlbum function from the Fetch data from the internet recipe. To test this function, make two changes:
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-3
Provide an http.Client to the function. This allows providing the correct http.Client depending on the situation. For Flutter and server-side projects, provide an http.IOClient. For Browser apps, provide an http.BrowserClient. For tests, provide a mock http.Client. Use the provided client to fetch data from the internet, rather than the static http.get() method, which is difficult to mock. The function should now look like this: In your app code, you can provide an http.Client to the fetchAlbum method directly with fetchAlbum(http.Client()). http.Client() creates a default http.Client. 3. Create a test file with a mock http.Client Next, create a test file. Following the advice in the Introduction to unit testing recipe, create a file called fetch_album_test.dart in the root test folder.
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-4
Add the annotation @GenerateMocks([http.Client]) to the main function to generate a MockClient class with mockito. The generated MockClient class implements the http.Client class. This allows you to pass the MockClient to the fetchAlbum function, and return different http responses in each test. The generated mocks will be located in fetch_album_test.mocks.dart. Import this file to use them. Next, generate the mocks running the following command: flutter pub run build_runner build 4. Write a test for each condition The fetchAlbum() function does one of two things: Returns an Album if the http call succeeds Throws an Exception if the http call fails
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-5
Throws an Exception if the http call fails Therefore, you want to test these two conditions. Use the MockClient class to return an “Ok” response for the success test, and an error response for the unsuccessful test. Test these conditions using the when() function provided by Mockito: 5. Run the tests Now that you have a fetchAlbum() function with tests in place, run the tests. flutter test test/fetch_album_test.dart You can also run tests inside your favorite editor by following the instructions in the Introduction to unit testing recipe. Complete example lib/main.dart test/fetch_album_test.dart Summary
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
64b454328c00-6
test/fetch_album_test.dart Summary In this example, you’ve learned how to use Mockito to test functions or classes that depend on web services or databases. This is only a short introduction to the Mockito library and the concept of mocking. For more information, see the documentation provided by the Mockito package. An introduction to unit testing An introduction to widget testing
https://docs.flutter.dev/cookbook/testing/unit/mocking/index.html
81b436c6cd64-0
An introduction to widget testing Handle scrolling Find widgets Cookbook Testing Widget Find widgets 1. Find a Text widget 2. Find a widget with a specific Key 3. Find a specific widget instance Summary Complete example To locate widgets in a test environment, use the Finder classes. While it’s possible to write your own Finder classes, it’s generally more convenient to locate widgets using the tools provided by the flutter_test package. During a flutter run session on a widget test, you can also interactively tap parts of the screen for the Flutter tool to print the suggested Finder.
https://docs.flutter.dev/cookbook/testing/widget/finders/index.html
81b436c6cd64-1
This recipe looks at the find constant provided by the flutter_test package, and demonstrates how to work with some of the Finders it provides. For a full list of available finders, see the CommonFinders documentation. If you’re unfamiliar with widget testing and the role of Finder classes, review the Introduction to widget testing recipe. This recipe uses the following steps: Find a Text widget. Find a widget with a specific Key. Find a specific widget instance. 1. Find a Text widget In testing, you often need to find widgets that contain specific text. This is exactly what the find.text() method is for. It creates a Finder that searches for widgets that display a specific String of text. 2. Find a widget with a specific Key
https://docs.flutter.dev/cookbook/testing/widget/finders/index.html
81b436c6cd64-2
2. Find a widget with a specific Key In some cases, you might want to find a widget based on the Key that has been provided to it. This can be handy if displaying multiple instances of the same widget. For example, a ListView might display several Text widgets that contain the same text. In this case, provide a Key to each widget in the list. This allows an app to uniquely identify a specific widget, making it easier to find the widget in the test environment. 3. Find a specific widget instance Finally, you might be interested in locating a specific instance of a widget. For example, this can be useful when creating widgets that take a child property and you want to ensure you’re rendering the child widget. Summary The find constant provided by the flutter_test package provides several ways to locate widgets in the test environment. This recipe demonstrated three of these methods, and several more methods exist for different purposes.
https://docs.flutter.dev/cookbook/testing/widget/finders/index.html
81b436c6cd64-3
If the above examples do not work for a particular use-case, see the CommonFinders documentation to review all available methods. Complete example An introduction to widget testing Handle scrolling
https://docs.flutter.dev/cookbook/testing/widget/finders/index.html
c4c286172998-0
Widget Cookbook Testing Widget An introduction to widget testing Find widgets Handle scrolling Tap, drag, and enter text
https://docs.flutter.dev/cookbook/testing/widget/index.html
9dda9d8aba75-0
Mock dependencies using Mockito Find widgets An introduction to widget testing Cookbook Testing Widget Introduction 1. Add the flutter_test dependency 2. Create a widget to test 3. Create a testWidgets test 4. Build the widget using the WidgetTester Notes about the pump() methods 5. Search for our widget using a Finder 6. Verify the widget using a Matcher Additional Matchers Complete example In the introduction to unit testing recipe, you learned how to test Dart classes using the test package. To test widget classes, you need a few additional tools provided by the flutter_test package, which ships with the Flutter SDK. The flutter_test package provides the following tools for testing widgets:
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-1
The flutter_test package provides the following tools for testing widgets: The WidgetTester allows building and interacting with widgets in a test environment. The testWidgets() function automatically creates a new WidgetTester for each test case, and is used in place of the normal test() function. The Finder classes allow searching for widgets in the test environment. Widget-specific Matcher constants help verify whether a Finder locates a widget or multiple widgets in the test environment. If this sounds overwhelming, don’t worry. Learn how all of these pieces fit together throughout this recipe, which uses the following steps: Add the flutter_test dependency. Create a widget to test. Create a testWidgets test. Build the widget using the WidgetTester. Search for the widget using a Finder. Verify the widget using a Matcher.
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-2
Verify the widget using a Matcher. 1. Add the flutter_test dependency Before writing tests, include the flutter_test dependency in the dev_dependencies section of the pubspec.yaml file. If creating a new Flutter project with the command line tools or a code editor, this dependency should already be in place. dev_dependencies flutter_test sdk flutter 2. Create a widget to test Next, create a widget for testing. For this recipe, create a widget that displays a title and message. 3. Create a testWidgets test With a widget to test, begin by writing your first test. Use the testWidgets() function provided by the flutter_test package to define a test. The testWidgets function allows you to define a widget test and creates a WidgetTester to work with.
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-3
This test verifies that MyWidget displays a given title and message. It is titled accordingly, and it will be populated in the next section. 4. Build the widget using the WidgetTester Next, build MyWidget inside the test environment by using the pumpWidget() method provided by WidgetTester. The pumpWidget method builds and renders the provided widget. Create a MyWidget instance that displays “T” as the title and “M” as the message. Notes about the pump() methods After the initial call to pumpWidget(), the WidgetTester provides additional ways to rebuild the same widget. This is useful if you’re working with a StatefulWidget or animations. For example, tapping a button calls setState(), but Flutter won’t automatically rebuild your widget in the test environment. Use one of the following methods to ask Flutter to rebuild the widget. tester.pump(Duration duration)
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-4
tester.pump(Duration duration) Schedules a frame and triggers a rebuild of the widget. If a Duration is specified, it advances the clock by that amount and schedules a frame. It does not schedule multiple frames even if the duration is longer than a single frame. Note: To kick off the animation, you need to call pump() once (with no duration specified) to start the ticker. Without it, the animation does not start. tester.pumpAndSettle() Repeatedly calls pump() with the given duration until there are no longer any frames scheduled. This, essentially, waits for all animations to complete. These methods provide fine-grained control over the build lifecycle, which is particularly useful while testing. 5. Search for our widget using a Finder
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-5
5. Search for our widget using a Finder With a widget in the test environment, search through the widget tree for the title and message Text widgets using a Finder. This allows verification that the widgets are being displayed correctly. For this purpose, use the top-level find() method provided by the flutter_test package to create the Finders. Since you know you’re looking for Text widgets, use the find.text() method. For more information about Finder classes, see the Finding widgets in a widget test recipe. 6. Verify the widget using a Matcher Finally, verify the title and message Text widgets appear on screen using the Matcher constants provided by flutter_test. Matcher classes are a core part of the test package, and provide a common way to verify a given value meets expectations. Ensure that the widgets appear on screen exactly one time. For this purpose, use the findsOneWidget Matcher.
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
9dda9d8aba75-6
Additional Matchers In addition to findsOneWidget, flutter_test provides additional matchers for common cases. findsNothing Verifies that no widgets are found. findsWidgets Verifies that one or more widgets are found. findsNWidgets Verifies that a specific number of widgets are found. matchesGoldenFile Verifies that a widget’s rendering matches a particular bitmap image (“golden file” testing). Complete example Mock dependencies using Mockito Find widgets
https://docs.flutter.dev/cookbook/testing/widget/introduction/index.html
93e3181251d6-0
Find widgets Tap, drag, and enter text Handle scrolling Cookbook Testing Widget Handle scrolling 1. Create an app with a list of items 2. Write a test that scrolls through the list 3. Run the test Many apps feature lists of content, from email clients to music apps and beyond. To verify that lists contain the expected content using widget tests, you need a way to scroll through lists to search for particular items. To scroll through lists via integration tests, use the methods provided by the WidgetTester class, which is included in the flutter_test package: In this recipe, learn how to scroll through a list of items to verify a specific widget is being displayed, and discuss the pros on cons of different approaches. This recipe uses the following steps: Create an app with a list of items.
https://docs.flutter.dev/cookbook/testing/widget/scrolling/index.html
93e3181251d6-1
Create an app with a list of items. Write a test that scrolls through the list. Run the test. 1. Create an app with a list of items This recipe builds an app that shows a long list of items. To keep this recipe focused on testing, use the app created in the Work with long lists recipe. If you’re unsure of how to work with long lists, see that recipe for an introduction. Add keys to the widgets you want to interact with inside the integration tests. 2. Write a test that scrolls through the list Now, you can write a test. In this example, scroll through the list of items and verify that a particular item exists in the list. The WidgetTester class provides the scrollUntilVisible() method, which scrolls through a list until a specific widget is visible. This is useful because the height of the items in the list can change depending on the device.
https://docs.flutter.dev/cookbook/testing/widget/scrolling/index.html
93e3181251d6-2
Rather than assuming that you know the height of all the items in a list, or that a particular widget is rendered on all devices, the scrollUntilVisible() method trepeatedly scrolls through a list of items until it finds what it’s looking for. The following code shows how to use the scrollUntilVisible() method to look through the list for a particular item. This code lives in a file called test/widget_test.dart. 3. Run the test Run the test using the following command from the root of the project: Find widgets Tap, drag, and enter text
https://docs.flutter.dev/cookbook/testing/widget/scrolling/index.html
e930bdab72ab-0
Handle scrolling Tap, drag, and enter text Cookbook Testing Widget Tap, drag, and enter text 1. Create a widget to test 2. Enter text in the text field 3. Ensure tapping a button adds the todo 4. Ensure swipe-to-dismiss removes the todo Complete example Many widgets not only display information, but also respond to user interaction. This includes buttons that can be tapped, and TextField for entering text. To test these interactions, you need a way to simulate them in the test environment. For this purpose, use the WidgetTester library. The WidgetTester provides methods for entering text, tapping, and dragging. enterText() tap() drag()
https://docs.flutter.dev/cookbook/testing/widget/tap-drag/index.html
e930bdab72ab-1
enterText() tap() drag() In many cases, user interactions update the state of the app. In the test environment, Flutter doesn’t automatically rebuild widgets when the state changes. To ensure that the widget tree is rebuilt after simulating a user interaction, call the pump() or pumpAndSettle() methods provided by the WidgetTester. This recipe uses the following steps: Create a widget to test. Enter text in the text field. Ensure tapping a button adds the todo. Ensure swipe-to-dismiss removes the todo. 1. Create a widget to test For this example, create a basic todo app that tests three features: Entering text into a TextField. Tapping a FloatingActionButton to add the text to a list of todos.
https://docs.flutter.dev/cookbook/testing/widget/tap-drag/index.html
e930bdab72ab-2
Tapping a FloatingActionButton to add the text to a list of todos. Swiping-to-dismiss to remove the item from the list. To keep the focus on testing, this recipe won’t provide a detailed guide on how to build the todo app. To learn more about how this app is built, see the relevant recipes: Create and style a text field Handle taps Create a basic list Implement swipe to dismiss 2. Enter text in the text field Now that you have a todo app, begin writing the test. Start by entering text into the TextField. Accomplish this task by: Building the widget in the test environment. Using the enterText() method from the WidgetTester.
https://docs.flutter.dev/cookbook/testing/widget/tap-drag/index.html
e930bdab72ab-3
Using the enterText() method from the WidgetTester. Note: This recipe builds upon previous widget testing recipes. To learn the core concepts of widget testing, see the following recipes: Introduction to widget testing Finding widgets in a widget test 3. Ensure tapping a button adds the todo After entering text into the TextField, ensure that tapping the FloatingActionButton adds the item to the list. This involves three steps: Tap the add button using the tap() method. Rebuild the widget after the state has changed using the pump() method. Ensure that the list item appears on screen. 4. Ensure swipe-to-dismiss removes the todo Finally, ensure that performing a swipe-to-dismiss action on the todo item removes it from the list. This involves three steps:
https://docs.flutter.dev/cookbook/testing/widget/tap-drag/index.html
e930bdab72ab-4
Use the drag() method to perform a swipe-to-dismiss action. Use the pumpAndSettle() method to continually rebuild the widget tree until the dismiss animation is complete. Ensure that the item no longer appears on screen. Complete example Handle scrolling
https://docs.flutter.dev/cookbook/testing/widget/tap-drag/index.html
21e3541f7424-0
Flutter Create Flutter Create is a contest that challenges you to build something interesting, inspiring, and beautiful with Flutter using 5KB or less of Dart code. Congratulations to all the winners this year! We were impressed by the ingenuity and creativity of your apps. For everyone who submitted an app, thank you. Share #FlutterCreate with your friends Flutter Create Highlight Reel All Winners Check out this article to read more about this year's results. Grand Prize Winner Compass by Zebiao Hu Category Winners Visual Beauty Relax by Erin Morrissey Code Quality Pocket Piano by Rody Davis Overall Execution TimeFlow by Fabian Stein Novelty
https://docs.flutter.dev/create/index.html
21e3541f7424-1
TimeFlow by Fabian Stein Novelty Events by Noel Jacob What to make: Create a novel experience with Flutter in 5KB or less of Dart code This contest is now closed. The winners will be announced at Google I/O 2019. Judging: Entries will be judged by a panel of Flutter experts against the following four criteria: Visual beauty Code quality Novelty of idea Overall execution Prizes: Grand prize: Fully-loaded Apple iMac Pro (worth over $10,000) 4 Winners: Google Home Max Up to 25 Winners: Google Home Mini
https://docs.flutter.dev/create/index.html
21e3541f7424-2
Up to 25 Winners: Google Home Mini In addition, all submissions will receive a digital certificate of completion. Submission guidelines: Your application must be submitted in the form of a ZIP file containing everything needed to run it on a target Android or iOS device. You should include a README.md file that includes a brief description of the application and any special instructions for running it (for example, if the application is designed for a specific platform target). Code should be licensed with an open source license (we recommend BSD, MIT or Apache), so that we can judge it and others can benefit from your work. We will run the application by unpacking the ZIP file and running the command flutter run --release to execute it on an attached Android or iOS device.
https://docs.flutter.dev/create/index.html
21e3541f7424-3
The ZIP file may contain other files and directories that are created using the flutter create command, such as pubspec.yaml; it may also include asset files (e.g. images, fonts) or data. We recommend running flutter clean before creating the ZIP file to strip out unnecessary binaries. With the exception of packages (see below), all executable content must be included in the ZIP file. All code needed to load and execute the application must be written in Dart, with the exception of any packages (as mentioned below). Dart code must appear in a file that has a filename ending in .dart. The total size of all Dart files in the ZIP file, excluding unit tests that are not executed, must be no more than 5,120 bytes as (for example) measured by the command find . -name "*.dart" | xargs cat | wc -c.
https://docs.flutter.dev/create/index.html
21e3541f7424-4
The application may use Flutter packages that are a) published on pub.dev; b) have broad applicability (e.g. not written solely for the purpose of circumventing the 5KB file limit, in the opinion of the judges). Contest rules: Full details and rules in our Official Rules. But here’s a quick summary of some of the key points: All work must be that of the contest entrant. Only one submission per entrant. Do not submit a project that already existed before the announcement of this contest. Entries may not be submitted by any person who is a minor at the time of entry. Google employees and contractors, contest judges, and members of their immediate families are not eligible to enter.
https://docs.flutter.dev/create/index.html
21e3541f7424-5
Persons from the following countries or regions can submit but will not be considered eligible for the contest due to local rules, including exclusion from judging and prizes: Italy, Brazil, Quebec, and Mexico. Submissions from the following embargoed countries will not be considered eligible for the contest, including exclusion from judging and prizes: Crimea, Cuba, Iran, Syria, North Korea, and Sudan. Entries will be collected via the website using an online form. Submissions must not be derogatory, offensive, threatening, defamatory, disparaging, libellous or contain any content that is inappropriate, indecent, sexual, profane, tortuous, slanderous, discriminatory in any way, or that promotes hatred or harm against any group or person, or otherwise does not comply with the theme and spirit of the contest.
https://docs.flutter.dev/create/index.html
21e3541f7424-6
They must not contain content, material or any element that is unlawful, or otherwise in violation of or contrary to all applicable federal, state, or local laws and regulation including the laws or regulations in any state where the doodle and supporting statement are created. They must not contain any content, material or element that displays any third party advertising, slogan, logo, trademark, representation of characters indicating a sponsorship or endorsement by a third party, commercial entity or that is not within the spirit of the Contest, as determined by Sponsor, in its sole discretion. They must be original, unpublished works that do not contain, incorporate or otherwise use any content, material or element that is owned by a third party or entity. They cannot contain any content, element, or material that violates a third party's publicity, privacy or intellectual property rights.
https://docs.flutter.dev/create/index.html
21e3541f7424-7
The submission is not the subject of any actual or threatened litigation or claim. The entrant does not include any disparaging remarks relating to the Sponsor or a third party. FAQ: What is Flutter Create? Flutter Create is a contest where new and experienced developers can submit a project built using Flutter. It’s a fun way to learn Flutter, try building out interfaces, and possibly win prizes. What is the judging criteria? Each entry will be rated against the following rubric: visual beauty, code quality, novelty of idea, and overall execution. Who are the judges? Entries will be judged by members of the Flutter team and experienced developers from the Flutter community. What are the deadlines for the project? You need to have your project submitted by April 7th at 11:59pm PDT (GMT-7).
https://docs.flutter.dev/create/index.html
21e3541f7424-8
I submitted my project, can I make changes to it? Yes, as long as your change occurs before April 7th at 11:59pm PDT (GMT-7). How will the winners be selected? Judges will evaluate the entries based on four criteria: visual beauty, code quality, novelty of idea, and overall execution. When will the winners be selected? Winners will be selected around April 25 and announced at Google I/O and online. What are the prizes? One grand prize winner will receive a customized iMac Pro 5K; Four additional winners will receive a Google Home Max; Up to 25 additional winners will receive a Google Home Mini. Can I submit more than one entry? We limit entries to one project per participant. We encourage you to submit your best entry!
https://docs.flutter.dev/create/index.html
21e3541f7424-9
I already have an approved app, can I submit that for the challenge? Unfortunately, no. Only new apps or UIs can be submitted for approval. Is there an age limit to participate? You must not be a minor (per your local law) to be eligible to win. Can you use Flare animations? If so, does it count towards the byte size? Image, video, font, and other binary asset types are not included in the 5KB Dart code limit. Can you store data in a separate file? For example, for a catalog of dogs, can you store the dog data in a json? Data is OK. However, we're counting all Dart code in the 5KB limit, so the JSON loader would be included. Do Flutter Create contest submissions have to be formatted by dartfmt?
https://docs.flutter.dev/create/index.html
21e3541f7424-10
Do Flutter Create contest submissions have to be formatted by dartfmt? We can run dartfmt on our side. We believe code quality is primarily driven by good structure, rather than indentation. But of course, if the code is impenetrable to the judges even after running dartfmt, it may be challenging for them to score it well for code quality. Can a team of people submit a single project? A team of people can submit a single project, but the person submitting the project through our form should be authorized to submit the project on behalf of the entire team or entity, and a winning project from a team is only eligible for 1 prize. Should we send just a .dart file or all the files as the given size is 5 kb and all the files would be above 5 kb? Please submit whatever it takes to build and run your application with `flutter run`.
https://docs.flutter.dev/create/index.html
21e3541f7424-11
Please submit whatever it takes to build and run your application with `flutter run`. Should the size of the app be 5kb after creating a zip file or without zipping the file? We are measuring Dart files, not the ZIP files, so the 5KB is measured without zipping the file. Do assets (art and audio) also have to be created by participants? All assets must comply with our Official Rules for submissions, and participants must either create or have permission to use and submit all parts of their submission. If I have more questions, where should I go? Take a look through our official rules. Create a novel user experience with Flutter using 5KB or less of Dart code Submit your app
https://docs.flutter.dev/create/index.html
e90e42685077-0
Who is Dash? How did it all start? Why a hummingbird? Dash facts This is Dash: Dash is the mascot for the Dart language and the Flutter framework. Note: You can now make your own digital Dash using Dashatar, a Flutter app for web and mobile! How did it all start? As soon as Shams Zakhour started working as a Dart writer at Google in December 2013, she started advocating for a Dart mascot. After documenting Java for 14 years, she had observed how beloved the Java mascot, Duke, had become, and she wanted something similar for Dart.
https://docs.flutter.dev/dash/index.html
e90e42685077-1
But the idea didn’t gain momentum until 2017, when one of the Flutter engineers, Nina Chen, suggested it on an internal mailing list. The Flutter VP at the time, Joshy Joseph, approved the idea and asked the organizer for the 2018 Dart Conference, Linda Rasmussen, to make it happen. Once Shams heard about these plans, she rushed to Linda and asked to own and drive the project to produce the plushies for the conference. Linda had already elicited some design sketches, which she handed off. Starting with the sketches, Shams located a vendor who could work within an aggressive deadline (competing with Lunar New Year), and started the process of creating the specs for the plushy. That’s right, Dash was originally a Dart mascot, not a Flutter mascot. Here are some early mockups and one of the first prototypes:
https://docs.flutter.dev/dash/index.html
e90e42685077-2
Here are some early mockups and one of the first prototypes: The first prototype had uneven eyes Why a hummingbird? Early on, a hummingbird image was created for the Dart team to use for presentations and the web. The hummingbird represents that Dart is a speedy language. However, hummingbirds are pointed and angular and we wanted a cuddly plushy, so we chose a round hummingbird. Shams specified which color would go where, the tail shape, the tuft of hair, the eyes…all the little details. The vendor sent the specs to two manufacturers who returned the prototypes some weeks later. Introducing Dash at the January 2018 Dart Conference:
https://docs.flutter.dev/dash/index.html
e90e42685077-3
Introducing Dash at the January 2018 Dart Conference: While the manufacturing process was proceeding, Shams chose a name for the plushy: Dash, because it was an early code name for the Dart project, it was gender neutral, and it seemed appropriate for a hummingbird. Many boxes of Dash plushies arrived in southern California just in time for the conference. They were eagerly adopted by Dart and Flutter enthusiasts. The people have spoken, so Dash is now the mascot for Flutter and Dart. Dash 1.0 Conference swag
https://docs.flutter.dev/dash/index.html
e90e42685077-4
Dash 1.0 Conference swag Since the creation of Dash 1.0, we’ve made two more versions. Marketing slightly changed the Dart and Flutter color scheme after Dash 1.0 was created, so Dash 2.0 reflects the updated scheme (which removed the green color). Dash 2.1 is a smaller size and has a few more color tweaks. The smaller size is easier to ship, and fits better in a claw machine! Dash 2.0 and 2.1 Dash facts Dash is female, but she doesn’t mind being called they, their, he, or him. Dash has an Instagram account. Dash has a straight beak. Please, don’t depict Dash with a curved beak.
https://docs.flutter.dev/dash/index.html
e90e42685077-5
We also have Mega-Dash, a life-sized mascot who is currently resting in a locked-down Google office. Mega-Dash made her first appearance at the Flutter Interact event in Brooklyn, New York, on December 11, 2019. We also have a Dash puppet that Shams made from one of the first plushies. A number of our YouTube videos feature the Dash puppet, voiced by Emily Fortuna, one of our early (and much loved) Flutter Developer Advocates.
https://docs.flutter.dev/dash/index.html
7fe2efb38663-0
Build and release an Android app Adding a launcher icon Enabling Material Components Signing the app Create an upload keystore Reference the keystore from the app Configure signing in gradle Shrinking your code with R8 Enabling multidex support Reviewing the app manifest Reviewing the Gradle build configuration Under the defaultConfig block Under the android block Building the app for release Build an app bundle Test the app bundle Offline using the bundle tool Online using Google Play Build an APK Install an APK on a device Publishing to the Google Play Store Updating the app’s version number Android release FAQ
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-1
Updating the app’s version number Android release FAQ When should I build app bundles versus APKs? What is a fat APK? What are the supported target architectures? How do I sign the app bundle created by flutter build appbundle? How do I build a release from within Android Studio? During a typical development cycle, you test an app using flutter run at the command line, or by using the Run and Debug options in your IDE. By default, Flutter builds a debug version of your app. When you’re ready to prepare a release version of your app, for example to publish to the Google Play Store, this page can help. Before publishing, you might want to put some finishing touches on your app. This page covers the following topics: Adding a launcher icon Enabling Material Components Signing the app Shrinking your code with R8 Enabling multidex support
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-2
Shrinking your code with R8 Enabling multidex support Reviewing the app manifest Reviewing the build configuration Building the app for release Publishing to the Google Play Store Updating the app’s version number Android release FAQ Note: Throughout this page, [project] refers to the directory that your application is in. While following these instructions, substitute [project] with your app’s directory. Adding a launcher icon When a new Flutter app is created, it has a default launcher icon. To customize this icon, you might want to check out the flutter_launcher_icons package. Alternatively, you can do it manually using the following steps: Review the Material Design product icons guidelines for icon design.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-3
Review the Material Design product icons guidelines for icon design. In the [project]/android/app/src/main/res/ directory, place your icon files in folders named using configuration qualifiers. The default mipmap- folders demonstrate the correct naming convention. In AndroidManifest.xml, update the application tag’s android:icon attribute to reference icons from the previous step (for example, <application android:icon="@mipmap/ic_launcher" ...). To verify that the icon has been replaced, run your app and inspect the app icon in the Launcher. Enabling Material Components If your app uses Platform Views, you may want to enable Material Components by following the steps described in the Getting Started guide for Android. For example: Add the dependency on Android’s Material in <my-app>/android/app/build.gradle: dependencies // ...
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-4
dependencies // ... implementation 'com.google.android.material:material:<version>' // ... To find out the latest version, visit Google Maven. Set the light theme in <my-app>/android/app/src/main/res/values/styles.xml: Set the dark theme in <my-app>/android/app/src/main/res/values-night/styles.xml <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar"> +<style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> Set the dark theme in <my-app>/android/app/src/main/res/values-night/styles.xml Signing the app <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-5
+<style name="NormalTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"> Signing the app To publish on the Play Store, you need to give your app a digital signature. Use the following instructions to sign your app. On Android, there are two signing keys: deployment and upload. The end-users download the .apk signed with the ‘deployment key’. An ‘upload key’ is used to authenticate the .aab / .apk uploaded by developers onto the Play Store and is re-signed with the deployment key once in the Play Store. It’s highly recommended to use the automatic cloud managed signing for the deployment key. For more information, see the official Play Store documentation. Create an upload keystore If you have an existing keystore, skip to the next step. If not, create one by either: Following the Android Studio key generation steps Running the following at the command line:
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-6
Running the following at the command line: On Mac/Linux, use the following command: keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload On Windows, use the following command: keytool -genkey -v -keystore %userprofile%\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload This command stores the upload-keystore.jks file in your home directory. If you want to store it elsewhere, change the argument you pass to the -keystore parameter. However, keep the keystore file private; don’t check it into public source control!
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-7
Note: The keytool command might not be in your path—it’s part of Java, which is installed as part of Android Studio. For the concrete path, run flutter doctor -v and locate the path printed after ‘Java binary at:’. Then use that fully qualified path replacing java (at the end) with keytool. If your path includes space-separated names, such as Program Files, use platform-appropriate notation for the names. For example, on Mac/Linux use Program\ Files, and on Windows use "Program Files". The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12. Reference the keystore from the app Create a file named [project]/android/key.properties that contains a reference to your keystore:
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-8
Warning: Keep the key.properties file private; don’t check it into public source control. Configure signing in gradle Configure gradle to use your upload key when building your app in release mode by editing the [project]/android/app/build.gradle file. Add the keystore information from your properties file before the android block: def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } android { ... } Load the key.properties file into the keystoreProperties object. Find the buildTypes block:
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-9
Find the buildTypes block: buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, // so `flutter run --release` works. signingConfig signingConfigs.debug } } And replace it with the following signing configuration info: signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } } Release builds of your app will now be signed automatically.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-10
Release builds of your app will now be signed automatically. Note: You may need to run flutter clean after changing the gradle file. This prevents cached builds from affecting the signing process. For more information on signing your app, see Sign your app on developer.android.com. Shrinking your code with R8 R8 is the new code shrinker from Google, and it’s enabled by default when you build a release APK or AAB. To disable R8, pass the --no-shrink flag to flutter build apk or flutter build appbundle. Note: Obfuscation and minification can considerably extend compile time of the Android application. Enabling multidex support
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-11
Enabling multidex support When writing large apps or making use of large plugins, you may encounter Android’s dex limit of 64k methods when targeting a minimum API of 20 or below. This may also be encountered when running debug versions of your app via flutter run that does not have shrinking enabled. Flutter tool supports easily enabling multidex. The simplest way is to opt into multidex support when prompted. The tool detects multidex build errors and will ask before making changes to your Android project. Opting in allows Flutter to automatically depend on androidx.multidex:multidex and use a generated FlutterMultiDexApplication as the project’s application. Note: Multidex support is natively included when targeting Android SDK 21 or later. However, it isn’t recommended to target API 21+ purely to resolve the multidex issue as this might inadvertently exclude users running older devices.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-12
You might also choose to manually support multidex by following Android’s guides and modifying your project’s Android directory configuration. A multidex keep file must be specified to include: Also, include any other classes used in app startup. See the official Android documentation for more detailed guidance on adding multidex support manually. Reviewing the app manifest Review the default App Manifest file, AndroidManifest.xml, located in [project]/android/app/src/main and verify that the values are correct, especially the following: Edit the android:label in the application tag to reflect the final name of the app. Add the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app. Reviewing the Gradle build configuration
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-13
Reviewing the Gradle build configuration Review the default Gradle build file (build.gradle) located in [project]/android/app to verify the values are correct: Under the defaultConfig block Specify the final, unique application ID Specify the minimum API level on which the app is designed to run. Defaults to flutter.minSdkVersion. Specify the target API level on which the app is designed to run. Defaults to flutter.targetSdkVersion. A positive integer used as an internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This version isn’t shown to users. A string used as the version number shown to users. This setting can be specified as a raw string or as a reference to a string resource.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-14
If you’re using Android plugin for Gradle 3.0.0 or higher, your project automatically uses the default version of the build tools that the plugin specifies. Alternatively, you can specify a version of the build tools. Under the android block Specify the API level Gradle should use to compile your app. Defaults to flutter.compileSdkVersion. For more information, see the module-level build section in the Gradle build file. Building the app for release You have two possible release formats when publishing to the Play Store. App bundle (preferred) APK Note: The Google Play Store prefers the app bundle format. For more information, see About Android App Bundles.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-15
Warning: Recently, the Flutter team has received several reports from developers indicating they are experiencing app crashes on certain devices on Android 6.0. If you are targeting Android 6.0, use the following steps: If you build an App Bundle Edit android/gradle.properties and add the flag: android.bundle.enableUncompressedNativeLibs=false. If you build an APK Make sure android/app/src/AndroidManifest.xml doesn’t set android:extractNativeLibs=false in the <application> tag. For more information, see the public issue. Build an app bundle
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-16
For more information, see the public issue. Build an app bundle This section describes how to build a release app bundle. If you completed the signing steps, the app bundle will be signed. At this point, you might consider obfuscating your Dart code to make it more difficult to reverse engineer. Obfuscating your code involves adding a couple flags to your build command, and maintaining additional files to de-obfuscate stack traces. From the command line: Enter cd [project] Run flutter build appbundle (Running flutter build defaults to a release build.) The release bundle for your app is created at [project]/build/app/outputs/bundle/release/app.aab.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-17
By default, the app bundle contains your Dart code and the Flutter runtime compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86-64 (x86 64-bit). Test the app bundle An app bundle can be tested in multiple ways—this section describes two. Offline using the bundle tool If you haven’t done so already, download bundletool from the GitHub repository. Generate a set of APKs from your app bundle. Deploy the APKs to connected devices. Online using Google Play Upload your bundle to Google Play to test it. You can use the internal test track, or the alpha or beta channels to test the bundle before releasing it in production. Follow these steps to upload your bundle to the Play Store.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-18
Follow these steps to upload your bundle to the Play Store. Build an APK Although app bundles are preferred over APKs, there are stores that don’t yet support app bundles. In this case, build a release APK for each target ABI (Application Binary Interface). If you completed the signing steps, the APK will be signed. At this point, you might consider obfuscating your Dart code to make it more difficult to reverse engineer. Obfuscating your code involves adding a couple flags to your build command. From the command line: Enter cd [project] Run flutter build apk --split-per-abi (The flutter build command defaults to --release.) This command results in three APK files: [project]/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-19
[project]/build/app/outputs/apk/release/app-arm64-v8a-release.apk [project]/build/app/outputs/apk/release/app-x86_64-release.apk Removing the --split-per-abi flag results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture. Install an APK on a device Follow these steps to install the APK on a connected Android device. From the command line: Connect your Android device to your computer with a USB cable. Enter cd [project]. Run flutter install. Publishing to the Google Play Store For detailed instructions on publishing your app to the Google Play Store, see the Google Play launch documentation.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-20
Updating the app’s version number The default version number of the app is 1.0.0. To update it, navigate to the pubspec.yaml file and update the following line: version: 1.0.0+1 The version number is three numbers separated by dots, such as 1.0.0 in the example above, followed by an optional build number such as 1 in the example above, separated by a +. Both the version and the build number may be overridden in Flutter’s build by specifying --build-name and --build-number, respectively. In Android, build-name is used as versionName while build-number used as versionCode. For more information, see Version your app in the Android documentation. When you rebuild the app for Android, any updates in the version number from the pubspec file will update the versionName and versionCode in the local.properties file. Android release FAQ
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-21
Android release FAQ Here are some commonly asked questions about deployment for Android apps. When should I build app bundles versus APKs? The Google Play Store recommends that you deploy app bundles over APKs because they allow a more efficient delivery of the application to your users. However, if you’re distributing your application by means other than the Play Store, an APK may be your only option. What is a fat APK? A fat APK is a single APK that contains binaries for multiple ABIs embedded within it. This has the benefit that the single APK runs on multiple architectures and thus has wider compatibility, but it has the drawback that its file size is much larger, causing users to download and store more bytes when installing your application. When building APKs instead of app bundles, it is strongly recommended to build split APKs, as described in build an APK using the --split-per-abi flag.
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-22
What are the supported target architectures? When building your application in release mode, Flutter apps can be compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86-64 (x86 64-bit). Flutter does not currently support building for x86 Android (See Issue 9253). How do I sign the app bundle created by flutter build appbundle? See Signing the app. How do I build a release from within Android Studio? In Android Studio, open the existing android/ folder under your app’s folder. Then, select build.gradle (Module: app) in the project panel: Next, select the build variant. Click Build > Select Build Variant in the main menu. Select any of the variants in the Build Variants panel (debug is the default):
https://docs.flutter.dev/deployment/android/index.html
7fe2efb38663-23
The resulting app bundle or APK files are located in build/app/outputs within your app’s folder.
https://docs.flutter.dev/deployment/android/index.html
1c300c13d3fc-0
Continuous delivery with Flutter CI/CD Options All-in-one options with built-in Flutter functionality Integrating fastlane with existing workflows fastlane Local setup Running deployment locally Cloud build and deploy setup Xcode Cloud Requirements Custom build script Post-clone script Workflow configuration Branch changes Next build number Follow continuous delivery best practices with Flutter to make sure your application is delivered to your beta testers and validated on a frequent basis without resorting to manual workflows. CI/CD Options There are a number of continuous integration (CI) and continuous delivery (CD) options available to help automate the delivery of your application. All-in-one options with built-in Flutter functionality Codemagic Bitrise Appcircle
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-1
Codemagic Bitrise Appcircle Integrating fastlane with existing workflows You can use fastlane with the following tooling: GitHub Actions Example: Flutter Gallery’s Github Actions workflows Example: Github Action in Flutter Project Cirrus Travis GitLab CircleCI Building and deploying Flutter apps with Fastlane This guide shows how to set up fastlane and then integrate it with your existing testing and continuous integration (CI) workflows. For more information, see “Integrating fastlane with existing workflow”. fastlane fastlane is an open-source tool suite to automate releases and deployments for your app. Local setup
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-2
Local setup It’s recommended that you test the build and deployment process locally before migrating to a cloud-based system. You could also choose to perform continuous delivery from a local machine. Install fastlane gem install fastlane or brew install fastlane. Visit the fastlane docs for more info. Create an environment variable named FLUTTER_ROOT, and set it to the root directory of your Flutter SDK. (This is required for the scripts that deploy for iOS.) Create your Flutter project, and when ready, make sure that your project builds via flutter build appbundle; and flutter build ipa. Initialize the fastlane projects for each platform. In your [project]/android directory, run fastlane init. In your [project]/ios directory, run fastlane init.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-3
Edit the Appfiles to ensure they have adequate metadata for your app. Check that package_name in [project]/android/fastlane/Appfile matches your package name in AndroidManifest.xml. Check that app_identifier in [project]/ios/fastlane/Appfile also matches Info.plist’s bundle identifier. Fill in apple_id, itc_team_id, team_id with your respective account info. Set up your local login credentials for the stores. Follow the Supply setup steps and ensure that fastlane supply init successfully syncs data from your Play Store console. Treat the .json file like your password and do not check it into any public source control repositories. Your iTunes Connect username is already in your Appfile’s apple_id field. Set the FASTLANE_PASSWORD shell environment variable with your iTunes Connect password. Otherwise, you’ll be prompted when uploading to iTunes/TestFlight.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-4
Set up code signing. Follow the Android app signing steps. On iOS, create and sign using a distribution certificate instead of a development certificate when you’re ready to test and deploy using TestFlight or App Store. Create and download a distribution certificate in your Apple Developer Account console. open [project]/ios/Runner.xcworkspace/ and select the distribution certificate in your target’s settings pane. Create a Fastfile script for each platform. On Android, follow the fastlane Android beta deployment guide. Your edit could be as simple as adding a lane that calls upload_to_play_store. Set the aab argument to ../build/app/outputs/bundle/release/app-release.aab to use the app bundle flutter build already built. On iOS, follow the fastlane iOS beta deployment guide. You can specify the archive path to avoid rebuilding the project. For example:
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-5
build_app( skip_build_archive: true, archive_path: "../build/ios/archive/Runner.xcarchive", ) upload_to_testflight You’re now ready to perform deployments locally or migrate the deployment process to a continuous integration (CI) system. Running deployment locally Build the release mode app. flutter build appbundle. flutter build ipa. Run the Fastfile script on each platform. cd android then fastlane [name of the lane you created]. cd ios then fastlane [name of the lane you created]. Cloud build and deploy setup First, follow the local setup section described in ‘Local setup’ to make sure the process works before migrating onto a cloud system like Travis.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-6
The main thing to consider is that since cloud instances are ephemeral and untrusted, you won’t be leaving your credentials like your Play Store service account JSON or your iTunes distribution certificate on the server. Continuous Integration (CI) systems generally support encrypted environment variables to store private data. You can pass these environment variables using --dart-define MY_VAR=MY_VALUE while building the app. Take precaution not to re-echo those variable values back onto the console in your test scripts. Those variables are also not available in pull requests until they’re merged to ensure that malicious actors cannot create a pull request that prints these secrets out. Be careful with interactions with these secrets in pull requests that you accept and merge.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-7
Make login credentials ephemeral. On Android: Remove the json_key_file field from Appfile and store the string content of the JSON in your CI system’s encrypted variable. Read the environment variable directly in your Fastfile. upload_to_play_store( ... json_key_data: ENV['<variable name>'] ) Serialize your upload key (for example, using base64) and save it as an encrypted environment variable. You can deserialize it on your CI system during the install phase with echo "$PLAY_STORE_UPLOAD_KEY" | base64 --decode > [path to your upload keystore] On iOS: Move the local environment variable FASTLANE_PASSWORD to use encrypted environment variables on the CI system. The CI system needs access to your distribution certificate. fastlane’s Match system is recommended to synchronize your certificates across machines.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-8
It’s recommended to use a Gemfile instead of using an indeterministic gem install fastlane on the CI system each time to ensure the fastlane dependencies are stable and reproducible between local and cloud machines. However, this step is optional. In both your [project]/android and [project]/ios folders, create a Gemfile containing the following content: source "https://rubygems.org" gem "fastlane" In both directories, run bundle update and check both Gemfile and Gemfile.lock into source control. When running locally, use bundle exec fastlane instead of fastlane.
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-9
Create the CI test script such as .travis.yml or .cirrus.yml in your repository root. See fastlane CI documentation for CI specific setup. Shard your script to run on both Linux and macOS platforms. During the setup phase of the CI task, do the following: Ensure Bundler is available using gem install bundler. Run bundle install in [project]/android or [project]/ios. Make sure the Flutter SDK is available and set in PATH. For Android, ensure the Android SDK is available and the ANDROID_SDK_ROOT path is set. For iOS, you may have to specify a dependency on Xcode (for example osx_image: xcode9.2). In the script phase of the CI task: Run flutter build appbundle or flutter build ios --release --no-codesign, depending on the platform. cd android or cd ios bundle exec fastlane [name of the lane] Xcode Cloud
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-10
bundle exec fastlane [name of the lane] Xcode Cloud Xcode Cloud is a continuous integration and delivery service for building, testing, and distributing apps and frameworks for Apple platforms. Requirements Xcode 13.4.1 or higher. Be enrolled in the Apple Developer Program. Custom build script Xcode Cloud recognizes custom build scripts that can be used to perform additional tasks at a designated time. It also includes a set of predefined environment variables, such as $CI_WORKSPACE, which is the location of your cloned repository. Note: The temporary build environment that Xcode Cloud uses includes tools that are part of macOS and Xcode—for example, Python—and additionally Homebrew to support installing third-party dependencies and tools. Post-clone script Leverage the post-clone custom build script that runs after Xcode Cloud clones your Git repository using the following instructions:
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-11
Create a file at ios/ci_scripts/ci_post_clone.sh and add the content below. This file should be added to your git repository and marked as executable. git add -chmod =+x ios/ci_scripts/ci_post_clone.sh Workflow configuration An Xcode Cloud workflow defines the steps performed in the CI/CD process when your workflow is triggered. Note: This requires that your project is already initialized with Git and linked to a remote repository. To create a new workflow in Xcode, use the following instructions: Choose Product > Xcode Cloud > Create Workflow to open the Create Workflow sheet. Select the product (app) that the workflow should be attached to, then click the Next button. The next sheet displays an overview of the default workflow provided by Xcode, and can be customized by clicking the Edit Workflow button. Branch changes
https://docs.flutter.dev/deployment/cd/index.html
1c300c13d3fc-12
Branch changes By default Xcode suggests the Branch Changes condition that starts a new build for every change to your Git repository’s default branch. For your app’s iOS variant, it’s reasonable that you would want Xcode Cloud to trigger your workflow after you’ve made changes to your flutter packages, or modified either the Dart or iOS source files within the lib\ and ios\ directories. This can be achieved by using the following Files and Folders conditions: Next build number Xcode Cloud defaults the build number for new workflows to 1 and increments it per successful build. If you’re using an existing app with a higher build number, you’ll need to configure Xcode Cloud to use the correct build number for it’s builds by simply specifying the Next Build Number in your iteration. Check out Setting the next build number for Xcode Cloud builds for more information.
https://docs.flutter.dev/deployment/cd/index.html