MOD: ooops, I needed to move the directories
This commit is contained in:
parent
5e28ef8ea5
commit
11dbdb162b
|
@ -1,27 +0,0 @@
|
|||
language: bash
|
||||
os:
|
||||
- osx
|
||||
env:
|
||||
- FLUTTER_CHANNEL="stable"
|
||||
- FLUTTER_CHANNEL="master"
|
||||
sudo: false
|
||||
before_script:
|
||||
- cd ..
|
||||
- git clone https://github.com/flutter/flutter.git -b $FLUTTER_CHANNEL
|
||||
- export PATH=$PATH:$PWD/flutter/bin:$PWD/flutter/bin/cache/dart-sdk/bin
|
||||
- cd -
|
||||
- flutter doctor
|
||||
script:
|
||||
- set -e # abort CI if an error happens
|
||||
- ./scripts/flutter_test.sh packages/provider
|
||||
- ./scripts/flutter_test.sh packages/provider/example
|
||||
|
||||
# export coverage
|
||||
- if [ $FLUTTER_CHANNEL = "stable" ]; then
|
||||
bash <(curl -s https://codecov.io/bash);
|
||||
fi
|
||||
matrix:
|
||||
fast_finish: true
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.pub-cache
|
|
@ -1,82 +0,0 @@
|
|||
include: package:pedantic/analysis_options.yaml
|
||||
analyzer:
|
||||
exclude:
|
||||
- "**/*.g.dart"
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
errors:
|
||||
todo: error
|
||||
include_file_not_found: ignore
|
||||
linter:
|
||||
rules:
|
||||
- public_member_api_docs
|
||||
- annotate_overrides
|
||||
- avoid_empty_else
|
||||
- avoid_function_literals_in_foreach_calls
|
||||
- avoid_init_to_null
|
||||
- avoid_null_checks_in_equality_operators
|
||||
- avoid_relative_lib_imports
|
||||
- avoid_renaming_method_parameters
|
||||
- avoid_return_types_on_setters
|
||||
- avoid_returning_null
|
||||
- avoid_types_as_parameter_names
|
||||
- avoid_unused_constructor_parameters
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
- cancel_subscriptions
|
||||
- cascade_invocations
|
||||
- comment_references
|
||||
- constant_identifier_names
|
||||
- control_flow_in_finally
|
||||
- directives_ordering
|
||||
- empty_catches
|
||||
- empty_constructor_bodies
|
||||
- empty_statements
|
||||
- hash_and_equals
|
||||
- implementation_imports
|
||||
- invariant_booleans
|
||||
- iterable_contains_unrelated_type
|
||||
- library_names
|
||||
- library_prefixes
|
||||
- list_remove_unrelated_type
|
||||
- no_adjacent_strings_in_list
|
||||
- no_duplicate_case_values
|
||||
- non_constant_identifier_names
|
||||
- null_closures
|
||||
- omit_local_variable_types
|
||||
- only_throw_errors
|
||||
- overridden_fields
|
||||
- package_api_docs
|
||||
- package_names
|
||||
- package_prefixed_library_names
|
||||
- prefer_adjacent_string_concatenation
|
||||
- prefer_collection_literals
|
||||
- prefer_conditional_assignment
|
||||
- prefer_const_constructors
|
||||
- prefer_contains
|
||||
- prefer_equal_for_default_values
|
||||
- prefer_final_fields
|
||||
- prefer_initializing_formals
|
||||
- prefer_interpolation_to_compose_strings
|
||||
- prefer_is_empty
|
||||
- prefer_is_not_empty
|
||||
- prefer_single_quotes
|
||||
- prefer_typing_uninitialized_variables
|
||||
- recursive_getters
|
||||
- slash_for_doc_comments
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- type_init_formals
|
||||
- unawaited_futures
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_const
|
||||
- unnecessary_getters_setters
|
||||
- unnecessary_lambdas
|
||||
- unnecessary_new
|
||||
- unnecessary_null_aware_assignments
|
||||
- unnecessary_statements
|
||||
- unnecessary_this
|
||||
- unrelated_type_equality_checks
|
||||
- use_rethrow_when_possible
|
||||
- valid_regexps
|
|
@ -1,14 +0,0 @@
|
|||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
android/
|
||||
ios/
|
||||
.packages
|
||||
# Remove the following pattern if you wish to check in your lock file
|
||||
pubspec.lock
|
||||
|
||||
# Conventional directory for build outputs
|
||||
build/
|
||||
coverage/
|
||||
|
||||
# Directory created by dartdoc
|
||||
doc/api/
|
|
@ -1,182 +0,0 @@
|
|||
[](https://travis-ci.org/rrousselGit/provider)
|
||||
[](https://pub.dartlang.org/packages/provider) [](https://codecov.io/gh/rrousselGit/provider) [](https://gitter.im/flutter_provider/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
A dependency injection system built with widgets for widgets. `provider` is mostly syntax sugar for `InheritedWidget`,
|
||||
to make common use-cases straightforward.
|
||||
|
||||
## Migration from v2.0.0 to v3.0.0
|
||||
|
||||
- Providers can no longer be instantiated with `const`.
|
||||
- `Provider` now throws if used with a `Listenable`/`Stream`.
|
||||
Consider using `ListenableProvider`/`StreamProvider` instead. Alternatively,
|
||||
this exception can be disabled by setting `Provider.debugCheckInvalidValueType`
|
||||
to `null` like so:
|
||||
|
||||
```dart
|
||||
void main() {
|
||||
Provider.debugCheckInvalidValueType = null;
|
||||
|
||||
runApp(MyApp());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
- All `XXProvider.value` constructors now use `value` as parameter name.
|
||||
|
||||
Before:
|
||||
|
||||
```dart
|
||||
ChangeNotifierProvider.value(notifier: myNotifier),
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```dart
|
||||
ChangeNotifierProvider.value(value: myNotifier),
|
||||
```
|
||||
|
||||
- `StreamProvider`'s default constructor now builds a `Stream` instead of `StreamController`. The previous behavior has been moved to the named constructor `StreamProvider.controller`.
|
||||
|
||||
Before:
|
||||
|
||||
```dart
|
||||
StreamProvider(builder: (_) => StreamController<int>()),
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```dart
|
||||
StreamProvider.controller(builder: (_) => StreamController<int>()),
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Exposing a value
|
||||
|
||||
To expose a variable using `provider`, wrap any widget into one of the provider widgets from this package
|
||||
and pass it your variable. Then, all descendants of the newly added provider widget can access this variable.
|
||||
|
||||
A simple example would be to wrap the entire application into a `Provider` widget and pass it our variable:
|
||||
|
||||
```dart
|
||||
Provider<String>.value(
|
||||
value: 'Hello World',
|
||||
child: MaterialApp(
|
||||
home: Home(),
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
Alternatively, for complex objects, most providers expose a constructor that takes a function to create the value.
|
||||
The provider will call that function only once, when inserting the widget in the tree, and expose the result.
|
||||
This is perfect for exposing a complex object that never changes over time without writing a `StatefulWidget`.
|
||||
|
||||
The following creates and exposes a `MyComplexClass`. And in the event where `Provider` is removed from the widget tree,
|
||||
the instantiated `MyComplexClass` will be disposed.
|
||||
|
||||
```dart
|
||||
Provider<MyComplexClass>(
|
||||
builder: (context) => MyComplexClass(),
|
||||
dispose: (context, value) => value.dispose()
|
||||
child: SomeWidget(),
|
||||
)
|
||||
```
|
||||
|
||||
### Reading a value
|
||||
|
||||
The easiest way to read a value is by using the static method `Provider.of<T>(BuildContext context)`. This method will look
|
||||
up in widget tree starting from the widget associated with the `BuildContext` passed and it will return the nearest variable
|
||||
of type `T` found (or throw if nothing if found).
|
||||
|
||||
Combined with the first example of [exposing a value](#exposing-a-value), this widget will read the exposed `String` and render "Hello World."
|
||||
|
||||
```dart
|
||||
class Home extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
/// Don't forget to pass the type of the object you want to obtain to `Provider.of`!
|
||||
Provider.of<String>(context)
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively instead of using `Provider.of`, we can use the `Consumer` widget.
|
||||
|
||||
This can be useful for performance optimizations or when it is difficult to obtain a `BuildContext` descendant of the provider.
|
||||
|
||||
```dart
|
||||
Provider<String>.value(
|
||||
value: 'Hello World',
|
||||
child: Consumer<String>(
|
||||
builder: (context, value, child) => Text(value),
|
||||
),
|
||||
);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Note that you can freely use multiple providers with different types together:
|
||||
|
||||
```dart
|
||||
Provider<int>.value(
|
||||
value: 42,
|
||||
child: Provider<String>.value(
|
||||
value: 'Hello World',
|
||||
child: // ...
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
And obtain their value independently:
|
||||
|
||||
```dart
|
||||
var value = Provider.of<int>(context);
|
||||
var value2 = Provider.of<String>(context);
|
||||
```
|
||||
|
||||
### MultiProvider
|
||||
|
||||
When injecting many values in big applications, `Provider` can rapidly become pretty nested:
|
||||
|
||||
```dart
|
||||
Provider<Foo>.value(
|
||||
value: foo,
|
||||
child: Provider<Bar>.value(
|
||||
value: bar,
|
||||
child: Provider<Baz>.value(
|
||||
value: baz,
|
||||
child: someWidget,
|
||||
)
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
In that situation, we can use `MultiProvider` to improve the readability:
|
||||
|
||||
```dart
|
||||
MultiProvider(
|
||||
providers: [
|
||||
Provider<Foo>.value(value: foo),
|
||||
Provider<Bar>.value(value: bar),
|
||||
Provider<Baz>.value(value: baz),
|
||||
],
|
||||
child: someWidget,
|
||||
)
|
||||
```
|
||||
|
||||
The behavior of both examples is strictly the same. `MultiProvider` only changes the appearance of the code.
|
||||
|
||||
### Existing providers
|
||||
|
||||
`provider` exposes a few different kinds of "provider" for different types of objects.
|
||||
|
||||
| name | description |
|
||||
| ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [Provider](https://pub.dartlang.org/documentation/provider/latest/provider/Provider-class.html) | The most basic form of provider. It takes a value and exposes it, whatever the value is. |
|
||||
| [ListenableProvider](https://pub.dartlang.org/documentation/provider/latest/provider/ListenableProvider-class.html) | A specific provider for Listenable object. ListenableProvider will listen to the object and ask widgets which depend on it to rebuild whenever the listener is called. |
|
||||
| [ChangeNotifierProvider](https://pub.dartlang.org/documentation/provider/latest/provider/ChangeNotifierProvider-class.html) | A specification of ListenableProvider for ChangeNotifier. It will automatically call `ChangeNotifier.dispose` when needed. |
|
||||
| [ValueListenableProvider](https://pub.dartlang.org/documentation/provider/latest/provider/ValueListenableProvider-class.html) | Listen to a ValueListenable and only expose `ValueListenable.value`. |
|
||||
| [StreamProvider](https://pub.dartlang.org/documentation/provider/latest/provider/StreamProvider-class.html) | Listen to a Stream and expose the latest value emitted. |
|
||||
| [FutureProvider](https://pub.dartlang.org/documentation/provider/latest/provider/FutureProvider-class.html) | Takes a `Future` and updates dependents when the future completes. |
|
|
@ -1,7 +0,0 @@
|
|||
cd $1
|
||||
flutter packages get
|
||||
flutter format --set-exit-if-changed lib test
|
||||
flutter analyze --no-current-package lib test/
|
||||
flutter test --no-pub --coverage
|
||||
# resets to the original state
|
||||
cd -
|
Loading…
Reference in New Issue