├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ └── main.dart ├── pubspec.yaml └── web │ ├── favicon.png │ ├── icons │ ├── Icon-192.png │ └── Icon-512.png │ ├── index.html │ └── manifest.json ├── lib ├── async_builder.dart ├── init_builder.dart └── src │ ├── async_builder.dart │ ├── common.dart │ └── init_builder.dart ├── pubspec.yaml └── test ├── async_builder_test.dart ├── common.dart └── init_builder_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | pubspec.lock 33 | 34 | # Android related 35 | **/android/**/gradle-wrapper.jar 36 | **/android/.gradle 37 | **/android/captures/ 38 | **/android/gradlew 39 | **/android/gradlew.bat 40 | **/android/local.properties 41 | **/android/**/GeneratedPluginRegistrant.java 42 | 43 | # iOS/XCode related 44 | **/ios/**/*.mode1v3 45 | **/ios/**/*.mode2v3 46 | **/ios/**/*.moved-aside 47 | **/ios/**/*.pbxuser 48 | **/ios/**/*.perspectivev3 49 | **/ios/**/*sync/ 50 | **/ios/**/.sconsign.dblite 51 | **/ios/**/.tags* 52 | **/ios/**/.vagrant/ 53 | **/ios/**/DerivedData/ 54 | **/ios/**/Icon? 55 | **/ios/**/Pods/ 56 | **/ios/**/.symlinks/ 57 | **/ios/**/profile 58 | **/ios/**/xcuserdata 59 | **/ios/.generated/ 60 | **/ios/Flutter/App.framework 61 | **/ios/Flutter/Flutter.framework 62 | **/ios/Flutter/Flutter.podspec 63 | **/ios/Flutter/Generated.xcconfig 64 | **/ios/Flutter/app.flx 65 | **/ios/Flutter/app.zip 66 | **/ios/Flutter/flutter_assets/ 67 | **/ios/Flutter/flutter_export_environment.sh 68 | **/ios/ServiceDefinitions.json 69 | **/ios/Runner/GeneratedPluginRegistrant.* 70 | 71 | # Exceptions to above rules. 72 | !**/ios/**/default.mode1v3 73 | !**/ios/**/default.mode2v3 74 | !**/ios/**/default.pbxuser 75 | !**/ios/**/default.perspectivev3 76 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 77 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 67826bdce54505760fe83b7ead70bdb5af6fe9f2 8 | channel: dev 9 | 10 | project_type: package -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [1.3.1+1] 2 | 3 | * Bump Dart SDK version 4 | 5 | ## [1.3.1] 6 | 7 | * Added a keepAlive flag to AsyncBuilder 8 | 9 | ## [1.3.0] 10 | 11 | * Migrated to null safety 12 | 13 | ## [1.2.1] 14 | 15 | * Added retain flag to AsyncBuilder 16 | 17 | ## [1.2.0] 18 | 19 | * Implemented InitBuilder 20 | * Bug fixes 21 | 22 | ## [1.1.0] 23 | 24 | * Added example 25 | * Bug fixes 26 | * Updated rxdart version constraints 27 | 28 | ## [1.0.0] - Initial release. 29 | 30 | * Implemented AsyncBuilder 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Andre Lipke 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the copyright holder nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # async_builder - Improved Future and Stream builder for Flutter. 2 | 3 | This package provides `AsyncBuilder`, a widget similar to StreamBuilder / FutureBuilder which is designed to reduce 4 | boilerplate and improve error handling. 5 | 6 | It also provides `InitBuilder`, which makes it easier to start async tasks safely. 7 | 8 | ## How to use 9 | 10 | **1. Add to dependencies** 11 | ``` 12 | dependencies: 13 | async_builder: ^1.2.0 14 | ``` 15 | 16 | **2. Import** 17 | ``` 18 | import 'package:async_builder/async_builder.dart'; 19 | import 'package:async_builder/init_builder.dart'; 20 | ``` 21 | 22 | ## AsyncBuilder Examples 23 | 24 | ### Future 25 | 26 | ```dart 27 | AsyncBuilder( 28 | future: myFuture, 29 | waiting: (context) => Text('Loading...'), 30 | builder: (context, value) => Text('$value'), 31 | error: (context, error, stackTrace) => Text('Error! $error'), 32 | ) 33 | ``` 34 | 35 | ### Stream 36 | 37 | ```dart 38 | AsyncBuilder( 39 | stream: myStream, 40 | waiting: (context) => Text('Loading...'), 41 | builder: (context, value) => Text('$value'), 42 | error: (context, error, stackTrace) => Text('Error! $error'), 43 | closed: (context, value) => Text('$value (closed)'), 44 | ) 45 | ``` 46 | 47 | Note that you cannot provide both a stream and future. 48 | 49 | ## AsyncBuilder Features 50 | 51 | ### Separate builders 52 | 53 | Instead of a single builder, AsyncBuilder allows you to specify separate builders depending on the state of the 54 | asynchronous operation: 55 | 56 | * `waiting(context)` - Called when no events have fired yet. 57 | * `builder(context, value)` - Required. Called when a value is available. 58 | * `error(context, error, stackTrace)` - Called if there was an error. 59 | * `closed(context, value)` - Called if the stream was closed. 60 | 61 | If any of these are not provided then it defaults to calling `builder` (potentially with a null `value`). 62 | 63 | ### Error handling 64 | 65 | AsyncBuilder does not silently ignore errors by default. 66 | 67 | If an exception occurs and `error` is provided, the widget will rebuild and call that builder. 68 | Otherwise, if `error` is not provided and `silent` not true then the exception and stack trace will be printed to 69 | console (default behavior). 70 | 71 | ### Initial value 72 | 73 | If `initial` is provided, it is used in place of the value before one is available. 74 | 75 | ### RxDart ValueStream 76 | 77 | If `stream` is a ValueStream (BehaviorSubject) holding an existing value, that value will be available immediately on 78 | first build. 79 | 80 | ### Stream pausing 81 | 82 | The `StreamSubscription` for this widget can be paused with the `pause` parameter, this is useful if you want to notify 83 | the upstream `StreamController` that you don't need updates. 84 | 85 | ## InitBuilder 86 | 87 | InitBuilder is a widget that initializes a value only when its configuration changes, this is extremely useful because 88 | it allows you to safely start async tasks without making a whole new StatefulWidget. 89 | 90 | The basic usage of this widget is to make a separate function outside of build that starts the task and then pass it to 91 | InitBuilder, for example: 92 | 93 | ```dart 94 | static Future getNumber() async => ...; 95 | 96 | build(context) => InitBuilder( 97 | getter: getNumber, 98 | builder: (context, future) => AsyncBuilder( 99 | future: future, 100 | builder: (context, value) => Text('$value'), 101 | ), 102 | ); 103 | ``` 104 | 105 | In this case, getNumber is only ever called on the first build. 106 | 107 | You may also want to pass arguments to the getter, for example to query shared preferences: 108 | 109 | ```dart 110 | final String prefsKey; 111 | 112 | build(context) => InitBuilder.arg( 113 | getter: sharedPrefs.getString, 114 | arg: prefsKey, 115 | builder: (context, future) => AsyncBuilder( 116 | future: future, 117 | builder: (context, value) => Text('$value'), 118 | ), 119 | ); 120 | ``` 121 | 122 | The alternate constructors `InitBuilder.arg` to `InitBuilder.arg7` can be used to pass arguments to the `getter`, these 123 | will re-initialize the value if and only if either `getter` or the arguments change. -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | errors: 3 | missing_required_param: warning 4 | missing_return: warning 5 | language: 6 | strict-casts: true 7 | strict-raw-types: true 8 | 9 | linter: 10 | rules: 11 | - always_declare_return_types 12 | - annotate_overrides 13 | - avoid_bool_literals_in_conditional_expressions 14 | - avoid_classes_with_only_static_members 15 | - avoid_empty_else 16 | - avoid_equals_and_hash_code_on_mutable_classes 17 | - avoid_field_initializers_in_const_classes 18 | - avoid_function_literals_in_foreach_calls 19 | - avoid_init_to_null 20 | - avoid_null_checks_in_equality_operators 21 | - avoid_relative_lib_imports 22 | - avoid_renaming_method_parameters 23 | - avoid_return_types_on_setters 24 | - avoid_returning_null_for_void 25 | - avoid_single_cascade_in_expression_statements 26 | - avoid_slow_async_io 27 | - avoid_types_as_parameter_names 28 | - avoid_unused_constructor_parameters 29 | - avoid_void_async 30 | - await_only_futures 31 | - camel_case_extensions 32 | - camel_case_types 33 | - cancel_subscriptions 34 | - control_flow_in_finally 35 | - directives_ordering 36 | - empty_catches 37 | - empty_constructor_bodies 38 | - empty_statements 39 | - flutter_style_todos 40 | - hash_and_equals 41 | - implementation_imports 42 | - iterable_contains_unrelated_type 43 | - library_names 44 | - library_prefixes 45 | - list_remove_unrelated_type 46 | - no_adjacent_strings_in_list 47 | - no_duplicate_case_values 48 | - non_constant_identifier_names 49 | - overridden_fields 50 | - package_api_docs 51 | - package_names 52 | - package_prefixed_library_names 53 | - prefer_adjacent_string_concatenation 54 | - prefer_asserts_in_initializer_lists 55 | - prefer_collection_literals 56 | - prefer_conditional_assignment 57 | - prefer_const_constructors 58 | - prefer_const_constructors_in_immutables 59 | - prefer_const_declarations 60 | - prefer_const_literals_to_create_immutables 61 | - prefer_contains 62 | - prefer_equal_for_default_values 63 | - prefer_final_fields 64 | - prefer_final_in_for_each 65 | - prefer_final_locals 66 | - prefer_for_elements_to_map_fromIterable 67 | - prefer_foreach 68 | - prefer_generic_function_type_aliases 69 | - prefer_if_elements_to_conditional_expressions 70 | - prefer_if_null_operators 71 | - prefer_initializing_formals 72 | - prefer_inlined_adds 73 | - prefer_is_empty 74 | - prefer_is_not_empty 75 | - prefer_is_not_operator 76 | - prefer_iterable_whereType 77 | - prefer_single_quotes 78 | - prefer_spread_collections 79 | - prefer_typing_uninitialized_variables 80 | - prefer_void_to_null 81 | - recursive_getters 82 | - slash_for_doc_comments 83 | - sort_pub_dependencies 84 | - sort_unnamed_constructors_first 85 | - test_types_in_equals 86 | - throw_in_finally 87 | - type_init_formals 88 | - unnecessary_brace_in_string_interps 89 | - unnecessary_const 90 | - unnecessary_getters_setters 91 | - unnecessary_new 92 | - unnecessary_null_aware_assignments 93 | - unnecessary_null_in_if_null_operators 94 | - unnecessary_overrides 95 | - unnecessary_parenthesis 96 | - unnecessary_statements 97 | - unnecessary_this 98 | - unrelated_type_equality_checks 99 | - use_full_hex_values_for_flutter_colors 100 | - use_key_in_widget_constructors 101 | - use_rethrow_when_possible 102 | - valid_regexps 103 | - void_checks 104 | - public_member_api_docs 105 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Exceptions to above rules. 44 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 45 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 2738a1148ba6c9a6114df62358109407c3ef2553 8 | channel: beta 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | errors: 3 | missing_required_param: warning 4 | missing_return: warning 5 | language: 6 | strict-casts: true 7 | strict-raw-types: true 8 | 9 | linter: 10 | rules: 11 | - always_declare_return_types 12 | - annotate_overrides 13 | - avoid_bool_literals_in_conditional_expressions 14 | - avoid_classes_with_only_static_members 15 | - avoid_empty_else 16 | - avoid_equals_and_hash_code_on_mutable_classes 17 | - avoid_field_initializers_in_const_classes 18 | - avoid_function_literals_in_foreach_calls 19 | - avoid_init_to_null 20 | - avoid_null_checks_in_equality_operators 21 | - avoid_relative_lib_imports 22 | - avoid_renaming_method_parameters 23 | - avoid_return_types_on_setters 24 | - avoid_returning_null_for_void 25 | - avoid_single_cascade_in_expression_statements 26 | - avoid_slow_async_io 27 | - avoid_types_as_parameter_names 28 | - avoid_unused_constructor_parameters 29 | - avoid_void_async 30 | - await_only_futures 31 | - camel_case_extensions 32 | - camel_case_types 33 | - cancel_subscriptions 34 | - control_flow_in_finally 35 | - directives_ordering 36 | - empty_catches 37 | - empty_constructor_bodies 38 | - empty_statements 39 | - flutter_style_todos 40 | - hash_and_equals 41 | - implementation_imports 42 | - iterable_contains_unrelated_type 43 | - library_names 44 | - library_prefixes 45 | - list_remove_unrelated_type 46 | - no_adjacent_strings_in_list 47 | - no_duplicate_case_values 48 | - non_constant_identifier_names 49 | - overridden_fields 50 | - package_api_docs 51 | - package_names 52 | - package_prefixed_library_names 53 | - prefer_adjacent_string_concatenation 54 | - prefer_asserts_in_initializer_lists 55 | - prefer_collection_literals 56 | - prefer_conditional_assignment 57 | - prefer_const_constructors 58 | - prefer_const_constructors_in_immutables 59 | - prefer_const_declarations 60 | - prefer_const_literals_to_create_immutables 61 | - prefer_contains 62 | - prefer_equal_for_default_values 63 | - prefer_final_fields 64 | - prefer_final_in_for_each 65 | - prefer_final_locals 66 | - prefer_for_elements_to_map_fromIterable 67 | - prefer_foreach 68 | - prefer_generic_function_type_aliases 69 | - prefer_if_elements_to_conditional_expressions 70 | - prefer_if_null_operators 71 | - prefer_initializing_formals 72 | - prefer_inlined_adds 73 | - prefer_is_empty 74 | - prefer_is_not_empty 75 | - prefer_is_not_operator 76 | - prefer_iterable_whereType 77 | - prefer_single_quotes 78 | - prefer_spread_collections 79 | - prefer_typing_uninitialized_variables 80 | - prefer_void_to_null 81 | - recursive_getters 82 | - slash_for_doc_comments 83 | - sort_pub_dependencies 84 | - sort_unnamed_constructors_first 85 | - test_types_in_equals 86 | - throw_in_finally 87 | - type_init_formals 88 | - unnecessary_brace_in_string_interps 89 | - unnecessary_const 90 | - unnecessary_getters_setters 91 | - unnecessary_new 92 | - unnecessary_null_aware_assignments 93 | - unnecessary_null_in_if_null_operators 94 | - unnecessary_overrides 95 | - unnecessary_parenthesis 96 | - unnecessary_statements 97 | - unnecessary_this 98 | - unrelated_type_equality_checks 99 | - use_full_hex_values_for_flutter_colors 100 | - use_rethrow_when_possible 101 | - valid_regexps 102 | - void_checks 103 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 28 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | lintOptions { 36 | disable 'InvalidPackage' 37 | } 38 | 39 | defaultConfig { 40 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 41 | applicationId "com.example.example" 42 | minSdkVersion 16 43 | targetSdkVersion 28 44 | versionCode flutterVersionCode.toInteger() 45 | versionName flutterVersionName 46 | } 47 | 48 | buildTypes { 49 | release { 50 | // TODO: Add your own signing config for the release build. 51 | // Signing with the debug keys for now, so `flutter run --release` works. 52 | signingConfig signingConfigs.debug 53 | } 54 | } 55 | } 56 | 57 | flutter { 58 | source '../..' 59 | } 60 | 61 | dependencies { 62 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 63 | } 64 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 8 | 12 | 19 | 23 | 27 | 32 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.5.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.enableR8=true 3 | android.useAndroidX=true 4 | android.enableJetifier=true 5 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Flutter Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | include ':app' 6 | 7 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 8 | def properties = new Properties() 9 | 10 | assert localPropertiesFile.exists() 11 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 12 | 13 | def flutterSdkPath = properties.getProperty("flutter.sdk") 14 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 15 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 16 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/app.flx 22 | Flutter/app.zip 23 | Flutter/flutter_assets/ 24 | Flutter/flutter_export_environment.sh 25 | ServiceDefinitions.json 26 | Runner/GeneratedPluginRegistrant.* 27 | 28 | # Exceptions to above rules. 29 | !default.mode1v3 30 | !default.mode2v3 31 | !default.pbxuser 32 | !default.perspectivev3 33 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 13 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 14 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 15 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 2147483647; 22 | dstPath = ""; 23 | dstSubfolderSpec = 10; 24 | files = ( 25 | ); 26 | name = "Embed Frameworks"; 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXCopyFilesBuildPhase section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 33 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 34 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 35 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 36 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 37 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 38 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 39 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 40 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 43 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 44 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 9740EEB11CF90186004384FC /* Flutter */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 62 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 63 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 64 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 65 | ); 66 | name = Flutter; 67 | sourceTree = ""; 68 | }; 69 | 97C146E51CF9000F007C117D = { 70 | isa = PBXGroup; 71 | children = ( 72 | 9740EEB11CF90186004384FC /* Flutter */, 73 | 97C146F01CF9000F007C117D /* Runner */, 74 | 97C146EF1CF9000F007C117D /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 97C146EF1CF9000F007C117D /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 97C146EE1CF9000F007C117D /* Runner.app */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 97C146F01CF9000F007C117D /* Runner */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 90 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 91 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 92 | 97C147021CF9000F007C117D /* Info.plist */, 93 | 97C146F11CF9000F007C117D /* Supporting Files */, 94 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 95 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 96 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 97 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 98 | ); 99 | path = Runner; 100 | sourceTree = ""; 101 | }; 102 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | 97C146ED1CF9000F007C117D /* Runner */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 115 | buildPhases = ( 116 | 9740EEB61CF901F6004384FC /* Run Script */, 117 | 97C146EA1CF9000F007C117D /* Sources */, 118 | 97C146EB1CF9000F007C117D /* Frameworks */, 119 | 97C146EC1CF9000F007C117D /* Resources */, 120 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 121 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = Runner; 128 | productName = Runner; 129 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | 97C146E61CF9000F007C117D /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastUpgradeCheck = 1020; 139 | ORGANIZATIONNAME = ""; 140 | TargetAttributes = { 141 | 97C146ED1CF9000F007C117D = { 142 | CreatedOnToolsVersion = 7.3.1; 143 | LastSwiftMigration = 1100; 144 | }; 145 | }; 146 | }; 147 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 148 | compatibilityVersion = "Xcode 9.3"; 149 | developmentRegion = en; 150 | hasScannedForEncodings = 0; 151 | knownRegions = ( 152 | en, 153 | Base, 154 | ); 155 | mainGroup = 97C146E51CF9000F007C117D; 156 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 157 | projectDirPath = ""; 158 | projectRoot = ""; 159 | targets = ( 160 | 97C146ED1CF9000F007C117D /* Runner */, 161 | ); 162 | }; 163 | /* End PBXProject section */ 164 | 165 | /* Begin PBXResourcesBuildPhase section */ 166 | 97C146EC1CF9000F007C117D /* Resources */ = { 167 | isa = PBXResourcesBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 171 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 172 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 173 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 174 | ); 175 | runOnlyForDeploymentPostprocessing = 0; 176 | }; 177 | /* End PBXResourcesBuildPhase section */ 178 | 179 | /* Begin PBXShellScriptBuildPhase section */ 180 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 181 | isa = PBXShellScriptBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | ); 185 | inputPaths = ( 186 | ); 187 | name = "Thin Binary"; 188 | outputPaths = ( 189 | ); 190 | runOnlyForDeploymentPostprocessing = 0; 191 | shellPath = /bin/sh; 192 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; 193 | }; 194 | 9740EEB61CF901F6004384FC /* Run Script */ = { 195 | isa = PBXShellScriptBuildPhase; 196 | buildActionMask = 2147483647; 197 | files = ( 198 | ); 199 | inputPaths = ( 200 | ); 201 | name = "Run Script"; 202 | outputPaths = ( 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | shellPath = /bin/sh; 206 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 207 | }; 208 | /* End PBXShellScriptBuildPhase section */ 209 | 210 | /* Begin PBXSourcesBuildPhase section */ 211 | 97C146EA1CF9000F007C117D /* Sources */ = { 212 | isa = PBXSourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 216 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXSourcesBuildPhase section */ 221 | 222 | /* Begin PBXVariantGroup section */ 223 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 224 | isa = PBXVariantGroup; 225 | children = ( 226 | 97C146FB1CF9000F007C117D /* Base */, 227 | ); 228 | name = Main.storyboard; 229 | sourceTree = ""; 230 | }; 231 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 232 | isa = PBXVariantGroup; 233 | children = ( 234 | 97C147001CF9000F007C117D /* Base */, 235 | ); 236 | name = LaunchScreen.storyboard; 237 | sourceTree = ""; 238 | }; 239 | /* End PBXVariantGroup section */ 240 | 241 | /* Begin XCBuildConfiguration section */ 242 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_ANALYZER_NONNULL = YES; 247 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 248 | CLANG_CXX_LIBRARY = "libc++"; 249 | CLANG_ENABLE_MODULES = YES; 250 | CLANG_ENABLE_OBJC_ARC = YES; 251 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 252 | CLANG_WARN_BOOL_CONVERSION = YES; 253 | CLANG_WARN_COMMA = YES; 254 | CLANG_WARN_CONSTANT_CONVERSION = YES; 255 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 256 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 257 | CLANG_WARN_EMPTY_BODY = YES; 258 | CLANG_WARN_ENUM_CONVERSION = YES; 259 | CLANG_WARN_INFINITE_RECURSION = YES; 260 | CLANG_WARN_INT_CONVERSION = YES; 261 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 262 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 263 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 264 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 265 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 266 | CLANG_WARN_STRICT_PROTOTYPES = YES; 267 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 268 | CLANG_WARN_UNREACHABLE_CODE = YES; 269 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 270 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 271 | COPY_PHASE_STRIP = NO; 272 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 273 | ENABLE_NS_ASSERTIONS = NO; 274 | ENABLE_STRICT_OBJC_MSGSEND = YES; 275 | GCC_C_LANGUAGE_STANDARD = gnu99; 276 | GCC_NO_COMMON_BLOCKS = YES; 277 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 278 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 279 | GCC_WARN_UNDECLARED_SELECTOR = YES; 280 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 281 | GCC_WARN_UNUSED_FUNCTION = YES; 282 | GCC_WARN_UNUSED_VARIABLE = YES; 283 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 284 | MTL_ENABLE_DEBUG_INFO = NO; 285 | SDKROOT = iphoneos; 286 | SUPPORTED_PLATFORMS = iphoneos; 287 | TARGETED_DEVICE_FAMILY = "1,2"; 288 | VALIDATE_PRODUCT = YES; 289 | }; 290 | name = Profile; 291 | }; 292 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 293 | isa = XCBuildConfiguration; 294 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 295 | buildSettings = { 296 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 297 | CLANG_ENABLE_MODULES = YES; 298 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 299 | ENABLE_BITCODE = NO; 300 | FRAMEWORK_SEARCH_PATHS = ( 301 | "$(inherited)", 302 | "$(PROJECT_DIR)/Flutter", 303 | ); 304 | INFOPLIST_FILE = Runner/Info.plist; 305 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 306 | LIBRARY_SEARCH_PATHS = ( 307 | "$(inherited)", 308 | "$(PROJECT_DIR)/Flutter", 309 | ); 310 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 311 | PRODUCT_NAME = "$(TARGET_NAME)"; 312 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 313 | SWIFT_VERSION = 5.0; 314 | VERSIONING_SYSTEM = "apple-generic"; 315 | }; 316 | name = Profile; 317 | }; 318 | 97C147031CF9000F007C117D /* Debug */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ALWAYS_SEARCH_USER_PATHS = NO; 322 | CLANG_ANALYZER_NONNULL = YES; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 328 | CLANG_WARN_BOOL_CONVERSION = YES; 329 | CLANG_WARN_COMMA = YES; 330 | CLANG_WARN_CONSTANT_CONVERSION = YES; 331 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 332 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INFINITE_RECURSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 338 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 339 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 341 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 342 | CLANG_WARN_STRICT_PROTOTYPES = YES; 343 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 344 | CLANG_WARN_UNREACHABLE_CODE = YES; 345 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 346 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 347 | COPY_PHASE_STRIP = NO; 348 | DEBUG_INFORMATION_FORMAT = dwarf; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | ENABLE_TESTABILITY = YES; 351 | GCC_C_LANGUAGE_STANDARD = gnu99; 352 | GCC_DYNAMIC_NO_PIC = NO; 353 | GCC_NO_COMMON_BLOCKS = YES; 354 | GCC_OPTIMIZATION_LEVEL = 0; 355 | GCC_PREPROCESSOR_DEFINITIONS = ( 356 | "DEBUG=1", 357 | "$(inherited)", 358 | ); 359 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 360 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 361 | GCC_WARN_UNDECLARED_SELECTOR = YES; 362 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 363 | GCC_WARN_UNUSED_FUNCTION = YES; 364 | GCC_WARN_UNUSED_VARIABLE = YES; 365 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 366 | MTL_ENABLE_DEBUG_INFO = YES; 367 | ONLY_ACTIVE_ARCH = YES; 368 | SDKROOT = iphoneos; 369 | TARGETED_DEVICE_FAMILY = "1,2"; 370 | }; 371 | name = Debug; 372 | }; 373 | 97C147041CF9000F007C117D /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 377 | CLANG_ANALYZER_NONNULL = YES; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 383 | CLANG_WARN_BOOL_CONVERSION = YES; 384 | CLANG_WARN_COMMA = YES; 385 | CLANG_WARN_CONSTANT_CONVERSION = YES; 386 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 387 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 388 | CLANG_WARN_EMPTY_BODY = YES; 389 | CLANG_WARN_ENUM_CONVERSION = YES; 390 | CLANG_WARN_INFINITE_RECURSION = YES; 391 | CLANG_WARN_INT_CONVERSION = YES; 392 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 393 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 394 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 395 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 396 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 397 | CLANG_WARN_STRICT_PROTOTYPES = YES; 398 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 399 | CLANG_WARN_UNREACHABLE_CODE = YES; 400 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 401 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 402 | COPY_PHASE_STRIP = NO; 403 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 404 | ENABLE_NS_ASSERTIONS = NO; 405 | ENABLE_STRICT_OBJC_MSGSEND = YES; 406 | GCC_C_LANGUAGE_STANDARD = gnu99; 407 | GCC_NO_COMMON_BLOCKS = YES; 408 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 409 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 410 | GCC_WARN_UNDECLARED_SELECTOR = YES; 411 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 412 | GCC_WARN_UNUSED_FUNCTION = YES; 413 | GCC_WARN_UNUSED_VARIABLE = YES; 414 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 415 | MTL_ENABLE_DEBUG_INFO = NO; 416 | SDKROOT = iphoneos; 417 | SUPPORTED_PLATFORMS = iphoneos; 418 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 419 | TARGETED_DEVICE_FAMILY = "1,2"; 420 | VALIDATE_PRODUCT = YES; 421 | }; 422 | name = Release; 423 | }; 424 | 97C147061CF9000F007C117D /* Debug */ = { 425 | isa = XCBuildConfiguration; 426 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 427 | buildSettings = { 428 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 429 | CLANG_ENABLE_MODULES = YES; 430 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 431 | ENABLE_BITCODE = NO; 432 | FRAMEWORK_SEARCH_PATHS = ( 433 | "$(inherited)", 434 | "$(PROJECT_DIR)/Flutter", 435 | ); 436 | INFOPLIST_FILE = Runner/Info.plist; 437 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 438 | LIBRARY_SEARCH_PATHS = ( 439 | "$(inherited)", 440 | "$(PROJECT_DIR)/Flutter", 441 | ); 442 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 443 | PRODUCT_NAME = "$(TARGET_NAME)"; 444 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 445 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 446 | SWIFT_VERSION = 5.0; 447 | VERSIONING_SYSTEM = "apple-generic"; 448 | }; 449 | name = Debug; 450 | }; 451 | 97C147071CF9000F007C117D /* Release */ = { 452 | isa = XCBuildConfiguration; 453 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 454 | buildSettings = { 455 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 456 | CLANG_ENABLE_MODULES = YES; 457 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 458 | ENABLE_BITCODE = NO; 459 | FRAMEWORK_SEARCH_PATHS = ( 460 | "$(inherited)", 461 | "$(PROJECT_DIR)/Flutter", 462 | ); 463 | INFOPLIST_FILE = Runner/Info.plist; 464 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 465 | LIBRARY_SEARCH_PATHS = ( 466 | "$(inherited)", 467 | "$(PROJECT_DIR)/Flutter", 468 | ); 469 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 470 | PRODUCT_NAME = "$(TARGET_NAME)"; 471 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 472 | SWIFT_VERSION = 5.0; 473 | VERSIONING_SYSTEM = "apple-generic"; 474 | }; 475 | name = Release; 476 | }; 477 | /* End XCBuildConfiguration section */ 478 | 479 | /* Begin XCConfigurationList section */ 480 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 481 | isa = XCConfigurationList; 482 | buildConfigurations = ( 483 | 97C147031CF9000F007C117D /* Debug */, 484 | 97C147041CF9000F007C117D /* Release */, 485 | 249021D3217E4FDB00AE95B9 /* Profile */, 486 | ); 487 | defaultConfigurationIsVisible = 0; 488 | defaultConfigurationName = Release; 489 | }; 490 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 491 | isa = XCConfigurationList; 492 | buildConfigurations = ( 493 | 97C147061CF9000F007C117D /* Debug */, 494 | 97C147071CF9000F007C117D /* Release */, 495 | 249021D4217E4FDB00AE95B9 /* Profile */, 496 | ); 497 | defaultConfigurationIsVisible = 0; 498 | defaultConfigurationName = Release; 499 | }; 500 | /* End XCConfigurationList section */ 501 | }; 502 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 503 | } 504 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:math'; 3 | 4 | import 'package:async_builder/async_builder.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | void main() { 8 | runApp(MyApp()); 9 | } 10 | 11 | class MyApp extends StatelessWidget { 12 | @override 13 | Widget build(BuildContext context) { 14 | return MaterialApp( 15 | title: 'Flutter Demo', 16 | theme: ThemeData( 17 | primarySwatch: Colors.blueGrey, 18 | visualDensity: VisualDensity.adaptivePlatformDensity, 19 | ), 20 | home: const MyHomePage(title: 'AsyncBuilder Example'), 21 | ); 22 | } 23 | } 24 | 25 | class MyHomePage extends StatefulWidget { 26 | const MyHomePage({Key? key, required this.title}) : super(key: key); 27 | 28 | final String title; 29 | 30 | @override 31 | _MyHomePageState createState() => _MyHomePageState(); 32 | } 33 | 34 | class _MyHomePageState extends State { 35 | @override 36 | Widget build(BuildContext context) { 37 | return Scaffold( 38 | appBar: AppBar( 39 | title: Text(widget.title), 40 | ), 41 | body: ListView( 42 | children: [ 43 | AsyncTestChild1(), 44 | AsyncTestChild2(), 45 | AsyncTestChild3(), 46 | AsyncTestChild4(), 47 | ], 48 | ), 49 | backgroundColor: Colors.blueGrey.shade600, 50 | ); 51 | } 52 | } 53 | 54 | class AsyncTestChild1 extends StatefulWidget { 55 | @override 56 | _AsyncTestChild1State createState() => _AsyncTestChild1State(); 57 | } 58 | 59 | class _AsyncTestChild1State extends State { 60 | Future? randomNumber; 61 | 62 | @override 63 | Widget build(BuildContext context) { 64 | final theme = Theme.of(context); 65 | final textTheme = theme.textTheme; 66 | return TestCard( 67 | title: 'Random Numbers - Future', 68 | desc: 69 | 'This example completes a future with a random number after 2 seconds.', 70 | child: Row(children: [ 71 | ElevatedButton( 72 | style: ElevatedButton.styleFrom( 73 | backgroundColor: Colors.blue, 74 | textStyle: const TextStyle(color: Colors.white), 75 | ), 76 | child: const Text('Generate'), 77 | onPressed: () { 78 | setState(() { 79 | randomNumber = Future.delayed( 80 | const Duration(seconds: 2), () => Random().nextInt(100)); 81 | }); 82 | }, 83 | ), 84 | const Padding(padding: EdgeInsets.only(right: 16)), 85 | if (randomNumber != null) 86 | AsyncBuilder( 87 | waiting: (context) => const CircularProgressIndicator(), 88 | builder: (context, i) => Text('$i', style: textTheme.titleLarge), 89 | future: randomNumber, 90 | ), 91 | ]), 92 | ); 93 | } 94 | } 95 | 96 | class AsyncTestChild2 extends StatefulWidget { 97 | @override 98 | _AsyncTestChild2State createState() => _AsyncTestChild2State(); 99 | } 100 | 101 | class _AsyncTestChild2State extends State { 102 | StreamController? randomNumber; 103 | 104 | void initController() { 105 | setState(() { 106 | randomNumber?.close(); 107 | randomNumber = StreamController(); 108 | }); 109 | } 110 | 111 | @override 112 | Widget build(BuildContext context) { 113 | final theme = Theme.of(context); 114 | final textTheme = theme.textTheme; 115 | return TestCard( 116 | title: 'Random Numbers - Stream', 117 | desc: 'This example adds a random number to a stream after 1 second.', 118 | child: Row(children: [ 119 | ElevatedButton( 120 | style: ElevatedButton.styleFrom( 121 | backgroundColor: Colors.blue, 122 | textStyle: const TextStyle(color: Colors.white), 123 | ), 124 | child: const Text('Reset'), 125 | onPressed: randomNumber == null 126 | ? null 127 | : () { 128 | setState(() { 129 | randomNumber = null; 130 | }); 131 | }, 132 | ), 133 | const Padding(padding: EdgeInsets.only(right: 8)), 134 | ElevatedButton( 135 | style: ElevatedButton.styleFrom( 136 | backgroundColor: Colors.blue, 137 | textStyle: const TextStyle(color: Colors.white), 138 | ), 139 | child: const Text('Add'), 140 | onPressed: () async { 141 | if (randomNumber == null) initController(); 142 | final ctrl = randomNumber; 143 | await Future.delayed(const Duration(seconds: 1)); 144 | ctrl!.add(Random().nextInt(100)); 145 | }, 146 | ), 147 | const Padding(padding: EdgeInsets.only(right: 16)), 148 | if (randomNumber != null) 149 | AsyncBuilder( 150 | waiting: (context) => const CircularProgressIndicator(), 151 | builder: (context, i) => Text('$i', style: textTheme.titleLarge), 152 | stream: randomNumber!.stream, 153 | ), 154 | ]), 155 | ); 156 | } 157 | } 158 | 159 | class AsyncTestChild3 extends StatefulWidget { 160 | @override 161 | _AsyncTestChild3State createState() => _AsyncTestChild3State(); 162 | } 163 | 164 | class _AsyncTestChild3State extends State { 165 | StreamController? randomNumber; 166 | 167 | void initController() { 168 | setState(() { 169 | randomNumber?.close(); 170 | final ctrl = StreamController(); 171 | randomNumber = ctrl; 172 | final timer = Timer.periodic(const Duration(milliseconds: 500), (timer) { 173 | ctrl.add(Random().nextInt(100)); 174 | }); 175 | ctrl.onCancel = timer.cancel; 176 | }); 177 | } 178 | 179 | @override 180 | Widget build(BuildContext context) { 181 | final theme = Theme.of(context); 182 | final textTheme = theme.textTheme; 183 | return TestCard( 184 | title: 'Random Numbers - Closing', 185 | desc: 186 | 'This example continuously adds numbers to a stream until it is closed.', 187 | child: Row(children: [ 188 | ElevatedButton( 189 | style: ElevatedButton.styleFrom( 190 | backgroundColor: Colors.blue, 191 | textStyle: const TextStyle(color: Colors.white), 192 | ), 193 | child: Text(randomNumber == null ? 'Start' : 'Restart'), 194 | onPressed: initController, 195 | ), 196 | const Padding(padding: EdgeInsets.only(right: 8)), 197 | ElevatedButton( 198 | style: ElevatedButton.styleFrom( 199 | backgroundColor: Colors.blue, 200 | textStyle: const TextStyle(color: Colors.white), 201 | ), 202 | child: const Text('Close'), 203 | onPressed: randomNumber == null || randomNumber!.isClosed 204 | ? null 205 | : () { 206 | setState(() { 207 | randomNumber!.close(); 208 | }); 209 | }, 210 | ), 211 | const Padding(padding: EdgeInsets.only(right: 16)), 212 | if (randomNumber != null) 213 | AsyncBuilder( 214 | waiting: (context) => const CircularProgressIndicator(), 215 | builder: (context, i) => Text('$i', style: textTheme.titleLarge), 216 | closed: (context, i) => 217 | Text('$i (Closed)', style: textTheme.titleLarge), 218 | stream: randomNumber!.stream, 219 | ), 220 | ]), 221 | ); 222 | } 223 | } 224 | 225 | class AsyncTestChild4 extends StatefulWidget { 226 | @override 227 | _AsyncTestChild4State createState() => _AsyncTestChild4State(); 228 | } 229 | 230 | class _AsyncTestChild4State extends State { 231 | StreamController? randomNumber; 232 | var pause = false; 233 | 234 | void initController() { 235 | setState(() { 236 | randomNumber?.close(); 237 | 238 | final ctrl = StreamController(); 239 | randomNumber = ctrl; 240 | 241 | late Timer timer; 242 | void start() { 243 | timer = Timer.periodic(const Duration(milliseconds: 500), (timer) { 244 | ctrl.add(Random().nextInt(100)); 245 | }); 246 | } 247 | 248 | ctrl.onPause = () => timer.cancel(); 249 | ctrl.onCancel = () => timer.cancel(); 250 | ctrl.onResume = start; 251 | 252 | start(); 253 | }); 254 | } 255 | 256 | @override 257 | Widget build(BuildContext context) { 258 | final theme = Theme.of(context); 259 | final textTheme = theme.textTheme; 260 | return TestCard( 261 | title: 'Random Numbers - Pausing', 262 | desc: 263 | 'This example continuously adds numbers to a stream but allows the subscription to be paused.', 264 | child: Row(children: [ 265 | ElevatedButton( 266 | style: ElevatedButton.styleFrom( 267 | backgroundColor: Colors.blue, 268 | textStyle: const TextStyle(color: Colors.white), 269 | ), 270 | child: Text(randomNumber == null ? 'Start' : 'Restart'), 271 | onPressed: initController, 272 | ), 273 | const Padding(padding: EdgeInsets.only(right: 16)), 274 | Text('Pause', style: textTheme.titleSmall), 275 | Switch( 276 | value: pause, 277 | onChanged: (b) { 278 | setState(() { 279 | pause = b; 280 | }); 281 | }, 282 | activeColor: Colors.blue), 283 | const Padding(padding: EdgeInsets.only(right: 16)), 284 | if (randomNumber != null) 285 | AsyncBuilder( 286 | waiting: (context) => const CircularProgressIndicator(), 287 | builder: (context, i) => Text('$i', style: textTheme.titleLarge), 288 | stream: randomNumber!.stream, 289 | pause: pause, 290 | ), 291 | ]), 292 | ); 293 | } 294 | } 295 | 296 | class TestCard extends StatelessWidget { 297 | final String title; 298 | final String desc; 299 | final Widget child; 300 | 301 | const TestCard({ 302 | required this.title, 303 | required this.desc, 304 | required this.child, 305 | }); 306 | 307 | @override 308 | Widget build(BuildContext context) { 309 | final theme = Theme.of(context); 310 | final textTheme = theme.textTheme; 311 | return Card( 312 | child: Padding( 313 | padding: const EdgeInsets.all(8), 314 | child: Column( 315 | crossAxisAlignment: CrossAxisAlignment.stretch, 316 | children: [ 317 | Padding( 318 | child: Text(title, style: textTheme.titleLarge), 319 | padding: const EdgeInsets.symmetric(vertical: 8), 320 | ), 321 | const Divider(), 322 | Text(desc, style: textTheme.titleMedium), 323 | const Padding(padding: EdgeInsets.only(bottom: 16)), 324 | child, 325 | ], 326 | )), 327 | ); 328 | } 329 | } 330 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | publish_to: 'none' 4 | 5 | version: 1.0.0+1 6 | 7 | environment: 8 | sdk: ">=2.16.0 <3.0.0" 9 | 10 | dependencies: 11 | async_builder: 12 | path: ../ 13 | flutter: 14 | sdk: flutter 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | 20 | flutter: 21 | uses-material-design: true 22 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingbird/async_builder/423e98cf36c681c443eef8aa2cdb6a4e3edd246a/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | example 18 | 19 | 20 | 21 | 24 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | } 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /lib/async_builder.dart: -------------------------------------------------------------------------------- 1 | export 'package:async_builder/src/async_builder.dart'; 2 | export 'package:async_builder/src/common.dart'; 3 | -------------------------------------------------------------------------------- /lib/init_builder.dart: -------------------------------------------------------------------------------- 1 | export 'package:async_builder/src/common.dart'; 2 | export 'package:async_builder/src/init_builder.dart'; 3 | -------------------------------------------------------------------------------- /lib/src/async_builder.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/widgets.dart'; 4 | import 'package:rxdart/rxdart.dart'; 5 | 6 | import 'common.dart'; 7 | 8 | /// A Widget that builds depending on the state of a [Future] or [Stream]. 9 | /// 10 | /// AsyncBuilder must be given either a [future] or [stream], not both. 11 | /// 12 | /// This is similar to [FutureBuilder] and [StreamBuilder] but accepts separate 13 | /// callbacks for each state. Just like the built in builders, the [future] or 14 | /// [stream] should not be created at build time because it would restart 15 | /// every time the ancestor is rebuilt. 16 | /// 17 | /// If [stream] is an rxdart [ValueStream] with an existing value, that value 18 | /// will be available on the first build. Otherwise when no data is available 19 | /// this builds either [waiting] if provided, or [builder] with a null value. 20 | /// 21 | /// If [initial] is provided, it is used in place of the value before one is 22 | /// available. 23 | /// 24 | /// If [retain] is true, the current value is retained when the [stream] or 25 | /// [future] instances change. Otherwise when [retain] is false or omitted, the 26 | /// value is reset. 27 | /// 28 | /// If the asynchronous operation completes with an error this builds [error]. 29 | /// If [error] is not provided [reportError] is called with the [FlutterErrorDetails]. 30 | /// 31 | /// When [stream] closes and [closed] is provided, [closed] is built with the 32 | /// last value emitted. 33 | /// 34 | /// If [pause] is true, the [StreamSubscription] used to listen to [stream] is 35 | /// paused. 36 | /// 37 | /// Example using [future]: 38 | /// 39 | /// ```dart 40 | /// AsyncBuilder( 41 | /// future: myFuture, 42 | /// waiting: (context) => Text('Loading...'), 43 | /// builder: (context, value) => Text('$value'), 44 | /// error: (context, error, stackTrace) => Text('Error! $error'), 45 | /// ) 46 | /// ``` 47 | /// 48 | /// Example using [stream]: 49 | /// 50 | /// ```dart 51 | /// AsyncBuilder( 52 | /// stream: myStream, 53 | /// waiting: (context) => Text('Loading...'), 54 | /// builder: (context, value) => Text('$value'), 55 | /// error: (context, error, stackTrace) => Text('Error! $error'), 56 | /// closed: (context, value) => Text('$value (closed)'), 57 | /// ) 58 | /// ``` 59 | class AsyncBuilder extends StatefulWidget { 60 | /// The builder that should be called when no data is available. 61 | final WidgetBuilder? waiting; 62 | 63 | /// The default value builder. 64 | final ValueBuilderFn builder; 65 | 66 | /// The builder that should be called when an error was thrown by the future 67 | /// or stream. 68 | final ErrorBuilderFn? error; 69 | 70 | /// The builder that should be called when the stream is closed. 71 | final ValueBuilderFn? closed; 72 | 73 | /// If provided, this is the future the widget listens to. 74 | final Future? future; 75 | 76 | /// If provided, this is the stream the widget listens to. 77 | final Stream? stream; 78 | 79 | /// The initial value used before one is available. 80 | final T? initial; 81 | 82 | /// Whether or not the current value should be retained when the [stream] or 83 | /// [future] instances change. 84 | final bool retain; 85 | 86 | /// Whether or not to suppress printing errors to the console. 87 | final bool silent; 88 | 89 | /// Whether or not to pause the stream subscription. 90 | final bool pause; 91 | 92 | /// If provided, overrides the function that prints errors to the console. 93 | final ErrorReporterFn reportError; 94 | 95 | /// Whether or not we should send a keep alive 96 | /// notification with [AutomaticKeepAliveClientMixin]. 97 | final bool keepAlive; 98 | 99 | /// Creates a widget that builds depending on the state of a [Future] or [Stream]. 100 | const AsyncBuilder({ 101 | Key? key, 102 | this.waiting, 103 | required this.builder, 104 | this.error, 105 | this.closed, 106 | this.future, 107 | this.stream, 108 | this.initial, 109 | this.retain = false, 110 | this.pause = false, 111 | bool? silent, 112 | this.keepAlive = false, 113 | ErrorReporterFn? reportError, 114 | }) : silent = silent ?? error != null, 115 | reportError = reportError ?? FlutterError.reportError, 116 | assert(!((future != null) && (stream != null)), 117 | 'AsyncBuilder should be given either a stream or future'), 118 | assert(future == null || closed == null, 119 | 'AsyncBuilder should not be given both a future and closed builder'), 120 | super(key: key); 121 | 122 | @override 123 | State createState() => _AsyncBuilderState(); 124 | } 125 | 126 | class _AsyncBuilderState extends State> 127 | with AutomaticKeepAliveClientMixin { 128 | T? _lastValue; 129 | Object? _lastError; 130 | StackTrace? _lastStackTrace; 131 | bool _hasFired = false; 132 | bool _isClosed = false; 133 | StreamSubscription? _subscription; 134 | 135 | void _cancel() { 136 | if (!widget.retain) { 137 | _lastValue = null; 138 | _lastError = null; 139 | _lastStackTrace = null; 140 | _hasFired = false; 141 | } 142 | _isClosed = false; 143 | _subscription?.cancel(); 144 | _subscription = null; 145 | } 146 | 147 | void _handleError(Object error, StackTrace? stackTrace) { 148 | _lastError = error; 149 | _lastStackTrace = stackTrace; 150 | if (widget.error != null && mounted) { 151 | setState(() {}); 152 | } 153 | if (!widget.silent) { 154 | widget.reportError(FlutterErrorDetails( 155 | exception: error, 156 | stack: stackTrace ?? StackTrace.empty, 157 | context: ErrorDescription('While updating AsyncBuilder'), 158 | )); 159 | } 160 | } 161 | 162 | void _initFuture() { 163 | _cancel(); 164 | final Future future = widget.future!; 165 | future.then((T value) { 166 | if (future != widget.future || !mounted) return; // Skip if future changed 167 | setState(() { 168 | _lastValue = value; 169 | _hasFired = true; 170 | }); 171 | }, onError: _handleError); 172 | } 173 | 174 | void _updatePause() { 175 | if (_subscription != null) { 176 | if (widget.pause && !_subscription!.isPaused) { 177 | _subscription!.pause(); 178 | } else if (!widget.pause && _subscription!.isPaused) { 179 | _subscription!.resume(); 180 | } 181 | } 182 | } 183 | 184 | void _initStream() { 185 | _cancel(); 186 | final Stream stream = widget.stream!; 187 | var skipFirst = false; 188 | if (stream is ValueStream && stream.hasValue) { 189 | skipFirst = true; 190 | _hasFired = true; 191 | _lastValue = stream.value; 192 | } 193 | _subscription = stream.listen( 194 | (T event) { 195 | if (skipFirst) { 196 | skipFirst = false; 197 | return; 198 | } 199 | setState(() { 200 | _hasFired = true; 201 | _lastValue = event; 202 | }); 203 | }, 204 | onDone: () { 205 | _isClosed = true; 206 | if (widget.closed != null) { 207 | setState(() {}); 208 | } 209 | }, 210 | onError: _handleError, 211 | ); 212 | } 213 | 214 | @override 215 | void initState() { 216 | super.initState(); 217 | 218 | if (widget.future != null) { 219 | _initFuture(); 220 | } else if (widget.stream != null) { 221 | _initStream(); 222 | _updatePause(); 223 | } 224 | } 225 | 226 | @override 227 | void didUpdateWidget(AsyncBuilder oldWidget) { 228 | super.didUpdateWidget(oldWidget); 229 | 230 | if (widget.future != null) { 231 | if (widget.future != oldWidget.future) _initFuture(); 232 | } else if (widget.stream != null) { 233 | if (widget.stream != oldWidget.stream) _initStream(); 234 | } else { 235 | _cancel(); 236 | } 237 | 238 | _updatePause(); 239 | } 240 | 241 | @override 242 | Widget build(BuildContext context) { 243 | super.build(context); 244 | 245 | if (_lastError != null && widget.error != null) { 246 | return widget.error!(context, _lastError!, _lastStackTrace); 247 | } 248 | 249 | if (_isClosed && widget.closed != null) { 250 | return widget.closed!(context, _hasFired ? _lastValue : widget.initial); 251 | } 252 | 253 | if (!_hasFired && widget.waiting != null) { 254 | return widget.waiting!(context); 255 | } 256 | 257 | return widget.builder(context, _hasFired ? _lastValue : widget.initial); 258 | } 259 | 260 | @override 261 | void dispose() { 262 | _cancel(); 263 | super.dispose(); 264 | } 265 | 266 | @override 267 | bool get wantKeepAlive => widget.keepAlive; 268 | } 269 | -------------------------------------------------------------------------------- /lib/src/common.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | /// Signature for a function that builds a widget from a value. 4 | typedef ValueBuilderFn = Widget Function(BuildContext context, T? value); 5 | 6 | /// Signature for a function that builds a widget from an exception. 7 | typedef ErrorBuilderFn = Widget Function( 8 | BuildContext context, Object error, StackTrace? stackTrace); 9 | 10 | /// Signature for a function that reports a flutter error, e.g. [FlutterError.reportError]. 11 | typedef ErrorReporterFn = void Function(FlutterErrorDetails details); 12 | -------------------------------------------------------------------------------- /lib/src/init_builder.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'common.dart'; 3 | 4 | /// A widget that initializes a value only when its configuration changes, 5 | /// useful for safe creation of async tasks. 6 | /// 7 | /// The default constructor takes a `getter`, `builder`, and `disposer`. The 8 | /// `getter` function is called to initialize the value used in `builder`. In 9 | /// this case InitBuilder only re-initializes the value if the `getter` function 10 | /// changes, you should not pass it an anonymous function directly. 11 | /// 12 | /// Alternative constructors [InitBuilder.arg] to [InitBuilder.arg7] can be used 13 | /// to pass arguments to the `getter`, these will re-initialize the value if 14 | /// either `getter` or the arguments change. 15 | /// 16 | /// The basic usage of this widget is to make a separate function outside of 17 | /// build that starts the task and then pass it to InitBuilder, for example: 18 | /// 19 | /// ```dart 20 | /// static Future getNumber() async => ...; 21 | /// 22 | /// Widget build(context) => InitBuilder( 23 | /// getter: getNumber, 24 | /// builder: (context, future) => AsyncBuilder( 25 | /// future: future, 26 | /// builder: (context, value) => Text('$value'), 27 | /// ), 28 | /// ); 29 | /// ``` 30 | /// 31 | /// You may also want to pass arguments to the getter, for example to query 32 | /// shared preferences: 33 | /// 34 | /// ```dart 35 | /// final String prefsKey; 36 | /// 37 | /// Widget build(context) => InitBuilder.arg( 38 | /// getter: sharedPrefs.getString, 39 | /// arg: prefsKey, 40 | /// builder: (context, future) => AsyncBuilder( 41 | /// future: future, 42 | /// builder: (context, value) => Text('$value'), 43 | /// ), 44 | /// ); 45 | /// ``` 46 | abstract class InitBuilder extends StatefulWidget { 47 | /// Builder that is called with a previously initialized value. 48 | final ValueBuilderFn builder; 49 | 50 | /// Function that is called with the value when the InitBuilder is being 51 | /// disposed. 52 | final ValueSetter? disposer; 53 | 54 | /// Factory constructor for a basic [InitBuilder]. 55 | factory InitBuilder({ 56 | Key? key, 57 | required ValueBuilderFn builder, 58 | required ValueGetter getter, 59 | ValueSetter? disposer, 60 | }) => 61 | _GetterInitBuilder( 62 | key: key, 63 | builder: builder, 64 | getter: getter, 65 | disposer: disposer, 66 | ); 67 | 68 | /// Base constructor for anything that implements [InitBuilder]. 69 | const InitBuilder.base({ 70 | Key? key, 71 | required this.builder, 72 | this.disposer, 73 | }) : super(key: key); 74 | 75 | /// Constructor for one argument getters. 76 | static InitBuilder arg({ 77 | Key? key, 78 | required ValueBuilderFn builder, 79 | required A arg, 80 | required T Function(A) getter, 81 | ValueSetter? disposer, 82 | }) => 83 | _ArgInitBuilder( 84 | key: key, 85 | builder: builder, 86 | arg: arg, 87 | getter: getter, 88 | disposer: disposer, 89 | ); 90 | 91 | /// Constructor for two argument getters. 92 | static InitBuilder arg2({ 93 | Key? key, 94 | required ValueBuilderFn builder, 95 | required A1 arg1, 96 | required A2 arg2, 97 | required T Function(A1, A2) getter, 98 | ValueSetter? disposer, 99 | }) => 100 | _Arg2InitBuilder( 101 | key: key, 102 | builder: builder, 103 | arg1: arg1, 104 | arg2: arg2, 105 | getter: getter, 106 | disposer: disposer, 107 | ); 108 | 109 | /// Constructor for three argument getters. 110 | static InitBuilder arg3({ 111 | Key? key, 112 | required ValueBuilderFn builder, 113 | required A1 arg1, 114 | required A2 arg2, 115 | required A3 arg3, 116 | required T Function(A1, A2, A3) getter, 117 | ValueSetter? disposer, 118 | }) => 119 | _Arg3InitBuilder( 120 | key: key, 121 | builder: builder, 122 | arg1: arg1, 123 | arg2: arg2, 124 | arg3: arg3, 125 | getter: getter, 126 | disposer: disposer, 127 | ); 128 | 129 | /// Constructor for four argument getters. 130 | static InitBuilder arg4({ 131 | Key? key, 132 | required ValueBuilderFn builder, 133 | required A1 arg1, 134 | required A2 arg2, 135 | required A3 arg3, 136 | required A4 arg4, 137 | required T Function(A1, A2, A3, A4) getter, 138 | ValueSetter? disposer, 139 | }) => 140 | _Arg4InitBuilder( 141 | key: key, 142 | builder: builder, 143 | arg1: arg1, 144 | arg2: arg2, 145 | arg3: arg3, 146 | arg4: arg4, 147 | getter: getter, 148 | disposer: disposer, 149 | ); 150 | 151 | /// Constructor for five argument getters. 152 | static InitBuilder arg5({ 153 | Key? key, 154 | required ValueBuilderFn builder, 155 | required A1 arg1, 156 | required A2 arg2, 157 | required A3 arg3, 158 | required A4 arg4, 159 | required A5 arg5, 160 | required T Function(A1, A2, A3, A4, A5) getter, 161 | ValueSetter? disposer, 162 | }) => 163 | _Arg5InitBuilder( 164 | key: key, 165 | builder: builder, 166 | arg1: arg1, 167 | arg2: arg2, 168 | arg3: arg3, 169 | arg4: arg4, 170 | arg5: arg5, 171 | getter: getter, 172 | disposer: disposer, 173 | ); 174 | 175 | /// Constructor for six argument getters. 176 | static InitBuilder arg6({ 177 | Key? key, 178 | required ValueBuilderFn builder, 179 | required A1 arg1, 180 | required A2 arg2, 181 | required A3 arg3, 182 | required A4 arg4, 183 | required A5 arg5, 184 | required A6 arg6, 185 | required T Function(A1, A2, A3, A4, A5, A6) getter, 186 | ValueSetter? disposer, 187 | }) => 188 | _Arg6InitBuilder( 189 | key: key, 190 | builder: builder, 191 | arg1: arg1, 192 | arg2: arg2, 193 | arg3: arg3, 194 | arg4: arg4, 195 | arg5: arg5, 196 | arg6: arg6, 197 | getter: getter, 198 | disposer: disposer, 199 | ); 200 | 201 | /// Constructor for seven argument getters. 202 | static InitBuilder arg7({ 203 | Key? key, 204 | required ValueBuilderFn builder, 205 | required A1 arg1, 206 | required A2 arg2, 207 | required A3 arg3, 208 | required A4 arg4, 209 | required A5 arg5, 210 | required A6 arg6, 211 | required A7 arg7, 212 | required T Function(A1, A2, A3, A4, A5, A6, A7) getter, 213 | ValueSetter? disposer, 214 | }) => 215 | _Arg7InitBuilder( 216 | key: key, 217 | builder: builder, 218 | arg1: arg1, 219 | arg2: arg2, 220 | arg3: arg3, 221 | arg4: arg4, 222 | arg5: arg5, 223 | arg6: arg6, 224 | arg7: arg7, 225 | getter: getter, 226 | disposer: disposer, 227 | ); 228 | 229 | /// Called by the widget state to initialize the value. 230 | T initValue(); 231 | 232 | /// Returns true if the value should be re-initialized after a rebuild. 233 | bool shouldInit(covariant InitBuilder other); 234 | 235 | @override 236 | _InitBuilderState createState() => _InitBuilderState(); 237 | } 238 | 239 | class _GetterInitBuilder extends InitBuilder { 240 | final ValueGetter getter; 241 | 242 | const _GetterInitBuilder({ 243 | Key? key, 244 | required ValueBuilderFn builder, 245 | required this.getter, 246 | ValueSetter? disposer, 247 | }) : super.base(key: key, builder: builder, disposer: disposer); 248 | 249 | @override 250 | T initValue() => getter(); 251 | 252 | @override 253 | bool shouldInit(_GetterInitBuilder other) => getter != other.getter; 254 | } 255 | 256 | class _ArgInitBuilder extends InitBuilder { 257 | final A arg; 258 | final T Function(A) getter; 259 | 260 | const _ArgInitBuilder({ 261 | Key? key, 262 | required ValueBuilderFn builder, 263 | required this.arg, 264 | required this.getter, 265 | ValueSetter? disposer, 266 | }) : super.base(key: key, builder: builder, disposer: disposer); 267 | 268 | @override 269 | T initValue() => getter(arg); 270 | 271 | @override 272 | bool shouldInit(_ArgInitBuilder other) => 273 | arg != other.arg || getter != other.getter; 274 | } 275 | 276 | class _Arg2InitBuilder extends InitBuilder { 277 | final A1 arg1; 278 | final A2 arg2; 279 | final T Function(A1, A2) getter; 280 | 281 | const _Arg2InitBuilder({ 282 | Key? key, 283 | required ValueBuilderFn builder, 284 | required this.arg1, 285 | required this.arg2, 286 | required this.getter, 287 | ValueSetter? disposer, 288 | }) : super.base(key: key, builder: builder, disposer: disposer); 289 | 290 | @override 291 | T initValue() => getter(arg1, arg2); 292 | 293 | @override 294 | bool shouldInit(_Arg2InitBuilder other) => 295 | arg1 != other.arg1 || arg2 != other.arg2 || getter != other.getter; 296 | } 297 | 298 | class _Arg3InitBuilder extends InitBuilder { 299 | final A1 arg1; 300 | final A2 arg2; 301 | final A3 arg3; 302 | final T Function(A1, A2, A3) getter; 303 | 304 | const _Arg3InitBuilder({ 305 | Key? key, 306 | required ValueBuilderFn builder, 307 | required this.arg1, 308 | required this.arg2, 309 | required this.arg3, 310 | required this.getter, 311 | ValueSetter? disposer, 312 | }) : super.base(key: key, builder: builder, disposer: disposer); 313 | 314 | @override 315 | T initValue() => getter(arg1, arg2, arg3); 316 | 317 | @override 318 | bool shouldInit(_Arg3InitBuilder other) => 319 | arg1 != other.arg1 || 320 | arg2 != other.arg2 || 321 | arg3 != other.arg3 || 322 | getter != other.getter; 323 | } 324 | 325 | class _Arg4InitBuilder extends InitBuilder { 326 | final A1 arg1; 327 | final A2 arg2; 328 | final A3 arg3; 329 | final A4 arg4; 330 | final T Function(A1, A2, A3, A4) getter; 331 | 332 | const _Arg4InitBuilder({ 333 | Key? key, 334 | required ValueBuilderFn builder, 335 | required this.arg1, 336 | required this.arg2, 337 | required this.arg3, 338 | required this.arg4, 339 | required this.getter, 340 | ValueSetter? disposer, 341 | }) : super.base(key: key, builder: builder, disposer: disposer); 342 | 343 | @override 344 | T initValue() => getter(arg1, arg2, arg3, arg4); 345 | 346 | @override 347 | bool shouldInit(_Arg4InitBuilder other) => 348 | arg1 != other.arg1 || 349 | arg2 != other.arg2 || 350 | arg3 != other.arg3 || 351 | arg4 != other.arg4 || 352 | getter != other.getter; 353 | } 354 | 355 | class _Arg5InitBuilder extends InitBuilder { 356 | final A1 arg1; 357 | final A2 arg2; 358 | final A3 arg3; 359 | final A4 arg4; 360 | final A5 arg5; 361 | final T Function(A1, A2, A3, A4, A5) getter; 362 | 363 | const _Arg5InitBuilder({ 364 | Key? key, 365 | required ValueBuilderFn builder, 366 | required this.arg1, 367 | required this.arg2, 368 | required this.arg3, 369 | required this.arg4, 370 | required this.arg5, 371 | required this.getter, 372 | ValueSetter? disposer, 373 | }) : super.base(key: key, builder: builder, disposer: disposer); 374 | 375 | @override 376 | T initValue() => getter(arg1, arg2, arg3, arg4, arg5); 377 | 378 | @override 379 | bool shouldInit(_Arg5InitBuilder other) => 380 | arg1 != other.arg1 || 381 | arg2 != other.arg2 || 382 | arg3 != other.arg3 || 383 | arg4 != other.arg4 || 384 | arg5 != other.arg5 || 385 | getter != other.getter; 386 | } 387 | 388 | class _Arg6InitBuilder extends InitBuilder { 389 | final A1 arg1; 390 | final A2 arg2; 391 | final A3 arg3; 392 | final A4 arg4; 393 | final A5 arg5; 394 | final A6 arg6; 395 | final T Function(A1, A2, A3, A4, A5, A6) getter; 396 | 397 | const _Arg6InitBuilder({ 398 | Key? key, 399 | required ValueBuilderFn builder, 400 | required this.arg1, 401 | required this.arg2, 402 | required this.arg3, 403 | required this.arg4, 404 | required this.arg5, 405 | required this.arg6, 406 | required this.getter, 407 | ValueSetter? disposer, 408 | }) : super.base(key: key, builder: builder, disposer: disposer); 409 | 410 | @override 411 | T initValue() => getter(arg1, arg2, arg3, arg4, arg5, arg6); 412 | 413 | @override 414 | bool shouldInit(_Arg6InitBuilder other) => 415 | arg1 != other.arg1 || 416 | arg2 != other.arg2 || 417 | arg3 != other.arg3 || 418 | arg4 != other.arg4 || 419 | arg5 != other.arg5 || 420 | arg6 != other.arg6 || 421 | getter != other.getter; 422 | } 423 | 424 | class _Arg7InitBuilder extends InitBuilder { 425 | final A1 arg1; 426 | final A2 arg2; 427 | final A3 arg3; 428 | final A4 arg4; 429 | final A5 arg5; 430 | final A6 arg6; 431 | final A7 arg7; 432 | final T Function(A1, A2, A3, A4, A5, A6, A7) getter; 433 | 434 | const _Arg7InitBuilder({ 435 | Key? key, 436 | required ValueBuilderFn builder, 437 | required this.arg1, 438 | required this.arg2, 439 | required this.arg3, 440 | required this.arg4, 441 | required this.arg5, 442 | required this.arg6, 443 | required this.arg7, 444 | required this.getter, 445 | ValueSetter? disposer, 446 | }) : super.base(key: key, builder: builder, disposer: disposer); 447 | 448 | @override 449 | T initValue() => getter(arg1, arg2, arg3, arg4, arg5, arg6, arg7); 450 | 451 | @override 452 | bool shouldInit(_Arg7InitBuilder other) => 453 | arg1 != other.arg1 || 454 | arg2 != other.arg2 || 455 | arg3 != other.arg3 || 456 | arg4 != other.arg4 || 457 | arg5 != other.arg5 || 458 | arg6 != other.arg6 || 459 | arg7 != other.arg7 || 460 | getter != other.getter; 461 | } 462 | 463 | class _InitBuilderState extends State> { 464 | T? value; 465 | 466 | @override 467 | void initState() { 468 | super.initState(); 469 | value = widget.initValue(); 470 | } 471 | 472 | @override 473 | void didUpdateWidget(InitBuilder oldWidget) { 474 | super.didUpdateWidget(oldWidget); 475 | if (widget.shouldInit(oldWidget)) { 476 | value = widget.initValue(); 477 | } 478 | } 479 | 480 | @override 481 | Widget build(BuildContext context) => widget.builder(context, value); 482 | 483 | @override 484 | void dispose() { 485 | if (widget.disposer != null) { 486 | widget.disposer!(value as T); 487 | } 488 | 489 | super.dispose(); 490 | } 491 | } 492 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: async_builder 2 | description: Flutter Future and Stream builder with less boilerplate and better error handling. 3 | version: 1.3.1+1 4 | homepage: https://github.com/PixelToast/async_builder 5 | 6 | environment: 7 | sdk: '>=2.16.0 <3.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | rxdart: ">=0.20.0 <1.0.0" 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | flutter: 19 | -------------------------------------------------------------------------------- /test/async_builder_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:async_builder/async_builder.dart'; 4 | import 'package:flutter/foundation.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter/rendering.dart'; 7 | import 'package:flutter/widgets.dart'; 8 | import 'package:flutter_test/flutter_test.dart'; 9 | import 'package:rxdart/rxdart.dart'; 10 | 11 | import 'common.dart'; 12 | 13 | void main() { 14 | group('AsyncBuilder', () { 15 | testWidgets('Stream', (tester) async { 16 | reportedErrors.clear(); 17 | final ctrl = StreamController(); 18 | 19 | await tester.pumpWidget(buildFrame(AsyncBuilder( 20 | waiting: (context) => const Text('waiting'), 21 | builder: (context, value) => Text('$value'), 22 | stream: ctrl.stream, 23 | reportError: reportError, 24 | ))); 25 | 26 | expect(tester.widget(findText).data, equals('waiting')); 27 | 28 | // Remove waiting builder 29 | 30 | await tester.pumpWidget(buildFrame(AsyncBuilder( 31 | builder: (context, value) => Text('$value'), 32 | stream: ctrl.stream, 33 | reportError: reportError, 34 | ))); 35 | 36 | expect(tester.widget(findText).data, equals('null')); 37 | 38 | // Add initial value 39 | 40 | await tester.pumpWidget(buildFrame(AsyncBuilder( 41 | initial: 'foo', 42 | builder: (context, value) => Text('$value'), 43 | stream: ctrl.stream, 44 | reportError: reportError, 45 | ))); 46 | 47 | expect(tester.widget(findText).data, equals('foo')); 48 | 49 | // Add events 50 | 51 | ctrl.add('bar'); 52 | await tester.pump(Duration.zero); 53 | expect(tester.widget(findText).data, equals('bar')); 54 | 55 | ctrl.add('potato'); 56 | await tester.pump(Duration.zero); 57 | expect(tester.widget(findText).data, equals('potato')); 58 | 59 | // Add error 60 | 61 | expect(reportedErrors, isEmpty); 62 | ctrl.addError('Test error message', StackTrace.current); 63 | 64 | await tester.pump(Duration.zero); 65 | 66 | expect(reportedErrors.single.exception, equals('Test error message')); 67 | reportedErrors.clear(); 68 | 69 | // Error builder 70 | 71 | await tester.pumpWidget(buildFrame(AsyncBuilder( 72 | initial: 'foo', 73 | builder: (context, value) => Text('$value'), 74 | stream: ctrl.stream, 75 | error: (context, error, stackTrace) => Text('$error'), 76 | reportError: reportError, 77 | ))); 78 | 79 | expect(tester.widget(findText).data, equals('Test error message')); 80 | 81 | // Stream closed 82 | 83 | ctrl.close(); 84 | 85 | await tester.pumpWidget(buildFrame(AsyncBuilder( 86 | initial: 'foo', 87 | builder: (context, value) => Text('$value'), 88 | stream: ctrl.stream, 89 | closed: (context, value) => Text('Closed $value'), 90 | reportError: reportError, 91 | ))); 92 | 93 | expect(tester.widget(findText).data, equals('Closed potato')); 94 | expect(reportedErrors, isEmpty); 95 | }); 96 | 97 | testWidgets('Stops listening when disposed', (tester) async { 98 | reportedErrors.clear(); 99 | final ctrl = StreamController(); 100 | 101 | await tester.pumpWidget(buildFrame(AsyncBuilder( 102 | builder: (context, value) => Text('$value'), 103 | stream: ctrl.stream, 104 | reportError: reportError, 105 | ))); 106 | 107 | expect(ctrl.hasListener, isTrue); 108 | 109 | await tester.pumpWidget(const SizedBox()); 110 | 111 | expect(ctrl.hasListener, isFalse); 112 | ctrl.close(); 113 | }); 114 | 115 | testWidgets('Stops listening when replaced', (tester) async { 116 | reportedErrors.clear(); 117 | final ctrl = StreamController(); 118 | final ctrl2 = StreamController(); 119 | 120 | // Listen to ctrl 121 | 122 | await tester.pumpWidget(buildFrame(AsyncBuilder( 123 | builder: (context, value) => Text('$value'), 124 | stream: ctrl.stream, 125 | reportError: reportError, 126 | ))); 127 | 128 | expect(ctrl.hasListener, isTrue); 129 | 130 | // Switch stream to ctrl2 131 | 132 | await tester.pumpWidget(buildFrame(AsyncBuilder( 133 | builder: (context, value) => Text('$value'), 134 | stream: ctrl2.stream, 135 | reportError: reportError, 136 | ))); 137 | 138 | expect(ctrl.hasListener, isFalse); 139 | expect(ctrl2.hasListener, isTrue); 140 | 141 | // Switch to future 142 | 143 | await tester.pumpWidget(buildFrame(AsyncBuilder( 144 | builder: (context, value) => Text('$value'), 145 | future: Future.value('foo'), 146 | reportError: reportError, 147 | ))); 148 | 149 | expect(ctrl2.hasListener, isFalse); 150 | 151 | await tester.pump(Duration.zero); 152 | expect(tester.widget(findText).data, equals('foo')); 153 | 154 | ctrl.close(); 155 | ctrl2.close(); 156 | }); 157 | 158 | testWidgets('Future', (tester) async { 159 | reportedErrors.clear(); 160 | final ctrl = Completer(); 161 | 162 | await tester.pumpWidget(buildFrame(AsyncBuilder( 163 | initial: 'waiting', 164 | builder: (context, value) => Text('$value'), 165 | future: ctrl.future, 166 | reportError: reportError, 167 | ))); 168 | 169 | expect(tester.widget(findText).data, equals('waiting')); 170 | 171 | // Complete future 172 | 173 | ctrl.complete('foo'); 174 | 175 | await tester.pump(Duration.zero); 176 | expect(tester.widget(findText).data, equals('foo')); 177 | }); 178 | 179 | testWidgets('Future error', (tester) async { 180 | reportedErrors.clear(); 181 | final ctrl = Completer(); 182 | 183 | await tester.pumpWidget(buildFrame(AsyncBuilder( 184 | initial: 'waiting', 185 | builder: (context, value) => Text('$value'), 186 | future: ctrl.future, 187 | reportError: reportError, 188 | ))); 189 | 190 | expect(tester.widget(findText).data, equals('waiting')); 191 | 192 | // Complete future 193 | 194 | ctrl.completeError('Test error message'); 195 | 196 | await tester.pump(Duration.zero); 197 | 198 | expect(reportedErrors.single.exception, equals('Test error message')); 199 | reportedErrors.clear(); 200 | 201 | // Error builder 202 | 203 | await tester.pumpWidget(buildFrame(AsyncBuilder( 204 | builder: (context, value) => Text('$value'), 205 | future: ctrl.future, 206 | error: (context, error, stackTrace) => Text('$error'), 207 | reportError: reportError, 208 | ))); 209 | 210 | expect(tester.widget(findText).data, equals('Test error message')); 211 | expect(reportedErrors, isEmpty); 212 | }); 213 | 214 | testWidgets('SynchronousFuture', (tester) async { 215 | reportedErrors.clear(); 216 | 217 | await tester.pumpWidget(buildFrame(AsyncBuilder( 218 | initial: 'waiting', 219 | builder: (context, value) => Text('$value'), 220 | future: SynchronousFuture('foo'), 221 | reportError: reportError, 222 | ))); 223 | 224 | expect(tester.widget(findText).data, equals('foo')); 225 | await tester.pump(Duration.zero); 226 | expect(tester.widget(findText).data, equals('foo')); 227 | expect(reportedErrors, isEmpty); 228 | }); 229 | 230 | testWidgets('Future complete after dispose', (tester) async { 231 | reportedErrors.clear(); 232 | final ctrl = Completer(); 233 | 234 | await tester.pumpWidget(buildFrame(AsyncBuilder( 235 | builder: (context, value) => Text('$value'), 236 | future: ctrl.future, 237 | reportError: reportError, 238 | ))); 239 | 240 | await tester.pumpWidget(const SizedBox()); 241 | 242 | ctrl.complete('foo'); 243 | 244 | await tester.pump(Duration.zero); 245 | expect(reportedErrors, isEmpty); 246 | }); 247 | 248 | testWidgets('Future errors after dispose', (tester) async { 249 | reportedErrors.clear(); 250 | final ctrl = Completer(); 251 | 252 | await tester.pumpWidget(buildFrame(AsyncBuilder( 253 | builder: (context, value) => Text('$value'), 254 | future: ctrl.future, 255 | reportError: reportError, 256 | ))); 257 | 258 | await tester.pumpWidget(const SizedBox()); 259 | 260 | ctrl.completeError('Test error message'); 261 | 262 | await tester.pump(Duration.zero); 263 | 264 | expect(reportedErrors.single.exception, equals('Test error message')); 265 | reportedErrors.clear(); 266 | }); 267 | 268 | testWidgets('Future errors after dispose with error builder', 269 | (tester) async { 270 | reportedErrors.clear(); 271 | final ctrl = Completer(); 272 | 273 | await tester.pumpWidget(buildFrame(AsyncBuilder( 274 | builder: (context, value) => Text('$value'), 275 | error: (context, error, stackTrace) => Text('$error'), 276 | future: ctrl.future, 277 | reportError: reportError, 278 | ))); 279 | 280 | await tester.pumpWidget(const SizedBox()); 281 | 282 | ctrl.completeError('Test error message'); 283 | 284 | await tester.pump(Duration.zero); 285 | 286 | expect(reportedErrors, isEmpty); 287 | }); 288 | 289 | testWidgets('BehaviorSubject', (tester) async { 290 | reportedErrors.clear(); 291 | final ctrl = BehaviorSubject.seeded('initial'); 292 | 293 | await tester.pumpWidget(buildFrame(AsyncBuilder( 294 | initial: 'waiting', 295 | builder: (context, value) => Text('$value'), 296 | stream: ctrl, 297 | reportError: reportError, 298 | ))); 299 | 300 | expect(tester.widget(findText).data, equals('initial')); 301 | 302 | ctrl.add('foo'); 303 | 304 | await tester.pump(Duration.zero); 305 | expect(tester.widget(findText).data, equals('foo')); 306 | 307 | // Remove AsyncBuilder 308 | 309 | await tester.pumpWidget(const SizedBox()); 310 | expect(ctrl.hasListener, isFalse); 311 | 312 | // Use ValueStream with existing value 313 | 314 | await tester.pumpWidget(buildFrame(AsyncBuilder( 315 | builder: (context, value) => Text('$value'), 316 | stream: ctrl, 317 | reportError: reportError, 318 | ))); 319 | 320 | expect(tester.widget(findText).data, equals('foo')); 321 | 322 | ctrl.add('bar'); 323 | 324 | await tester.pump(Duration.zero); 325 | expect(tester.widget(findText).data, equals('bar')); 326 | 327 | ctrl.close(); 328 | expect(reportedErrors, isEmpty); 329 | }); 330 | 331 | testWidgets('Pausing', (tester) async { 332 | reportedErrors.clear(); 333 | var paused = false; 334 | 335 | final ctrl = StreamController( 336 | onPause: () => paused = true, 337 | onResume: () => paused = false, 338 | ); 339 | 340 | await tester.pumpWidget(buildFrame(AsyncBuilder( 341 | builder: (context, value) => Text('$value'), 342 | stream: ctrl.stream, 343 | reportError: reportError, 344 | pause: true, 345 | ))); 346 | 347 | expect(paused, isTrue); 348 | 349 | await tester.pumpWidget(buildFrame(AsyncBuilder( 350 | builder: (context, value) => Text('$value'), 351 | stream: ctrl.stream, 352 | reportError: reportError, 353 | pause: false, 354 | ))); 355 | 356 | expect(paused, isFalse); 357 | ctrl.close(); 358 | expect(reportedErrors, isEmpty); 359 | }); 360 | 361 | testWidgets('No Stream or Future', (tester) async { 362 | reportedErrors.clear(); 363 | 364 | await tester.pumpWidget(buildFrame(AsyncBuilder( 365 | builder: (context, value) => Text('$value'), 366 | reportError: reportError, 367 | ))); 368 | 369 | expect(tester.widget(findText).data, equals('null')); 370 | 371 | await tester.pumpWidget(buildFrame(AsyncBuilder( 372 | waiting: (context) => const Text('waiting'), 373 | builder: (context, value) => Text('$value'), 374 | reportError: reportError, 375 | ))); 376 | 377 | expect(tester.widget(findText).data, equals('waiting')); 378 | 379 | expect(reportedErrors, isEmpty); 380 | }); 381 | 382 | testWidgets('Retains value', (tester) async { 383 | reportedErrors.clear(); 384 | 385 | final ctrl = Completer(); 386 | final ctrl2 = Completer(); 387 | 388 | await tester.pumpWidget(buildFrame(AsyncBuilder( 389 | future: ctrl.future, 390 | retain: true, 391 | waiting: (context) => const Text('waiting'), 392 | builder: (context, value) => Text('$value'), 393 | reportError: reportError, 394 | ))); 395 | 396 | expect(tester.widget(findText).data, equals('waiting')); 397 | 398 | ctrl.complete('hello'); 399 | await tester.pump(Duration.zero); 400 | 401 | expect(tester.widget(findText).data, equals('hello')); 402 | 403 | await tester.pumpWidget(buildFrame(AsyncBuilder( 404 | future: ctrl2.future, 405 | retain: true, 406 | waiting: (context) => const Text('waiting'), 407 | builder: (context, value) => Text('$value'), 408 | reportError: reportError, 409 | ))); 410 | 411 | expect(tester.widget(findText).data, equals('hello')); 412 | 413 | await tester.pump(Duration.zero); 414 | 415 | expect(tester.widget(findText).data, equals('hello')); 416 | 417 | ctrl2.complete('world'); 418 | await tester.pump(Duration.zero); 419 | 420 | expect(tester.widget(findText).data, equals('world')); 421 | 422 | expect(reportedErrors, isEmpty); 423 | }); 424 | 425 | testWidgets('Doesnt retain value', (tester) async { 426 | reportedErrors.clear(); 427 | 428 | final ctrl = Completer(); 429 | final ctrl2 = Completer(); 430 | 431 | await tester.pumpWidget(buildFrame(AsyncBuilder( 432 | future: ctrl.future, 433 | waiting: (context) => const Text('waiting'), 434 | builder: (context, value) => Text('$value'), 435 | reportError: reportError, 436 | ))); 437 | 438 | expect(tester.widget(findText).data, equals('waiting')); 439 | 440 | ctrl.complete('hello'); 441 | await tester.pump(Duration.zero); 442 | 443 | expect(tester.widget(findText).data, equals('hello')); 444 | 445 | await tester.pumpWidget(buildFrame(AsyncBuilder( 446 | future: ctrl2.future, 447 | waiting: (context) => const Text('waiting'), 448 | builder: (context, value) => Text('$value'), 449 | reportError: reportError, 450 | ))); 451 | 452 | expect(tester.widget(findText).data, equals('waiting')); 453 | 454 | await tester.pump(Duration.zero); 455 | 456 | expect(tester.widget(findText).data, equals('waiting')); 457 | 458 | ctrl2.complete('world'); 459 | await tester.pump(Duration.zero); 460 | 461 | expect(tester.widget(findText).data, equals('world')); 462 | 463 | expect(reportedErrors, isEmpty); 464 | }); 465 | 466 | testWidgets('Keeps alive when keepAlive is true', (tester) async { 467 | reportedErrors.clear(); 468 | 469 | final ctrl = Completer(); 470 | 471 | bool getKeepAlive() { 472 | final keepAliveElement = find 473 | .byElementPredicate( 474 | (e) => e.widget is KeepAlive, 475 | skipOffstage: false, 476 | ) 477 | .evaluate() 478 | .single; 479 | final renderObject = keepAliveElement.findRenderObject()!; 480 | return (renderObject.parentData as KeepAliveParentDataMixin).keepAlive; 481 | } 482 | 483 | Widget build(bool keepAlive) { 484 | return buildFrame( 485 | ListView( 486 | children: [ 487 | AsyncBuilder( 488 | future: ctrl.future, 489 | builder: (context, value) => const SizedBox(), 490 | reportError: reportError, 491 | keepAlive: keepAlive, 492 | ), 493 | ], 494 | ), 495 | ); 496 | } 497 | 498 | await tester.pumpWidget(build(false)); 499 | 500 | expect( 501 | getKeepAlive(), 502 | isFalse, 503 | ); 504 | 505 | await tester.pumpWidget(build(true)); 506 | 507 | expect( 508 | getKeepAlive(), 509 | isTrue, 510 | ); 511 | }); 512 | }); 513 | } 514 | -------------------------------------------------------------------------------- /test/common.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | 4 | final findText = find.byType(Text); 5 | 6 | Widget buildFrame(Widget child) { 7 | return Directionality( 8 | textDirection: TextDirection.ltr, 9 | child: child, 10 | ); 11 | } 12 | 13 | final reportedErrors = []; 14 | 15 | void reportError(FlutterErrorDetails details) { 16 | reportedErrors.add(details); 17 | } 18 | -------------------------------------------------------------------------------- /test/init_builder_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:async_builder/init_builder.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter/widgets.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | 6 | import 'common.dart'; 7 | 8 | void main() { 9 | group('InitBuilder', () { 10 | testWidgets('Basic getter', (tester) async { 11 | var getterCount = 42; 12 | var disposerCount = 0; 13 | 14 | int getInt() => getterCount++; 15 | 16 | await tester.pumpWidget(buildFrame(InitBuilder( 17 | getter: getInt, 18 | builder: (context, value) => Text('$value'), 19 | disposer: (e) => disposerCount += e, 20 | ))); 21 | 22 | expect(tester.widget(findText).data, equals('42')); 23 | 24 | // Make sure getter is not called again on rebuild 25 | 26 | await tester.pumpWidget(buildFrame(InitBuilder( 27 | getter: getInt, 28 | builder: (context, value) => Text('$value'), 29 | disposer: (e) => disposerCount += e, 30 | ))); 31 | 32 | expect(tester.widget(findText).data, equals('42')); 33 | 34 | // Change getter, expect it to be called 35 | 36 | int getInt2() => getterCount++; 37 | 38 | await tester.pumpWidget(buildFrame(InitBuilder( 39 | getter: getInt2, 40 | builder: (context, value) => Text('$value'), 41 | disposer: (e) => disposerCount += e, 42 | ))); 43 | 44 | expect(tester.widget(findText).data, equals('43')); 45 | 46 | /// Make sure disposer works 47 | 48 | await tester.pumpWidget(const SizedBox()); 49 | 50 | expect(disposerCount, equals(43)); 51 | }); 52 | 53 | testWidgets('Arg getter', (tester) async { 54 | var getterCount = 0; 55 | String? disposedValue; 56 | 57 | void disposer(String value) { 58 | expect(disposedValue, isNull); 59 | disposedValue = value; 60 | } 61 | 62 | String getString(String prefix, int offset) => 63 | '$prefix${offset + getterCount++}'; 64 | 65 | await tester.pumpWidget(buildFrame(InitBuilder.arg2( 66 | getter: getString, 67 | arg1: 'foo', 68 | arg2: 42, 69 | builder: (context, value) => Text(value!), 70 | disposer: disposer, 71 | ))); 72 | 73 | expect(tester.widget(findText).data, equals('foo42')); 74 | 75 | // Make sure getter is not called again on rebuild 76 | 77 | await tester.pumpWidget(buildFrame(InitBuilder.arg2( 78 | getter: getString, 79 | arg1: 'foo', 80 | arg2: 42, 81 | builder: (context, value) => Text(value!), 82 | disposer: disposer, 83 | ))); 84 | 85 | expect(tester.widget(findText).data, equals('foo42')); 86 | 87 | // Change arg, expect getter to be called 88 | 89 | await tester.pumpWidget(buildFrame(InitBuilder.arg2( 90 | getter: getString, 91 | arg1: 'foobar', 92 | arg2: 42, 93 | builder: (context, value) => Text(value!), 94 | disposer: disposer, 95 | ))); 96 | 97 | expect(tester.widget(findText).data, equals('foobar43')); 98 | 99 | /// Make sure disposer works 100 | 101 | await tester.pumpWidget(const SizedBox()); 102 | 103 | expect(disposedValue, equals('foobar43')); 104 | }); 105 | }); 106 | } 107 | --------------------------------------------------------------------------------