Skip to content

Commit

Permalink
Merge pull request #47 from filiph/master
Browse files Browse the repository at this point in the history
Apply `dartfmt --fix` and add automated test for Dart style
  • Loading branch information
brianegan committed Nov 30, 2018
2 parents 2553f64 + 280b179 commit 10b8abd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 48 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,7 @@ before_script:
- git clone https://github.com/flutter/flutter.git -b master --depth 1
- ./flutter/bin/flutter doctor
script:
- ./flutter/bin/cache/dart-sdk/bin/dartfmt -n --set-exit-if-changed ./lib ./test ./example ./exampleAsyncAndTest || travis_terminate 1
- ./flutter/bin/flutter test --coverage --coverage-path=lcov.info
after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Expand Up @@ -12,7 +12,7 @@ import '../lib/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp(model: CounterModel()));
await tester.pumpWidget(MyApp(model: CounterModel()));

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down
33 changes: 16 additions & 17 deletions exampleAsyncAndTest/lib/main.dart
Expand Up @@ -3,7 +3,7 @@ import 'package:scoped_model/scoped_model.dart';
import 'dart:async';

void main() {
runApp(new MyApp(model: CounterModel()));
runApp(MyApp(model: CounterModel()));
}

class MyApp extends StatelessWidget {
Expand All @@ -16,14 +16,14 @@ class MyApp extends StatelessWidget {
// At the top level of our app, we'll, create a ScopedModel Widget. This
// will provide the CounterModel to all children in the app that request it
// using a ScopedModelDescendant.
return new ScopedModel<AbstractModel>(
return ScopedModel<AbstractModel>(
model: model,
child: new MaterialApp(
child: MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
theme: ThemeData(
primarySwatch: Colors.green,
),
home: new CounterHome('Scoped Model Demo'),
home: CounterHome('Scoped Model Demo'),
),
);
}
Expand Down Expand Up @@ -72,37 +72,36 @@ class CounterHome extends StatelessWidget {

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(title),
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: new Center(
child: new Column(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
Text(
'You have pushed the button this many times:',
),
// Create a ScopedModelDescendant. This widget will get the
// CounterModel from the nearest parent ScopedModel<CounterModel>.
// It will hand that CounterModel to our builder method, and
// rebuild any time the CounterModel changes (i.e. after we
// `notifyListeners` in the Model).
new ScopedModelDescendant<AbstractModel>(
builder: (context, child, model) => new Text(
model.counter.toString(),
ScopedModelDescendant<AbstractModel>(
builder: (context, child, model) => Text(model.counter.toString(),
style: Theme.of(context).textTheme.display1),
),
],
),
),
// Use the ScopedModelDescendant again in order to use the increment
// method from the CounterModel
floatingActionButton: new ScopedModelDescendant<AbstractModel>(
builder: (context, child, model) => new FloatingActionButton(
floatingActionButton: ScopedModelDescendant<AbstractModel>(
builder: (context, child, model) => FloatingActionButton(
onPressed: model.increment,
tooltip: 'Increment',
child: new Icon(Icons.add),
child: Icon(Icons.add),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions exampleAsyncAndTest/test/widget_test.dart
Expand Up @@ -14,7 +14,7 @@ void main() {
'Counter increments test with the CounterModel => FAIL because the model contains an async function called',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp(model: CounterModel()));
await tester.pumpWidget(MyApp(model: CounterModel()));

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand All @@ -32,7 +32,7 @@ void main() {
testWidgets('Counter increments test with the TestModel => SUCCESS',
(WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp(model: TestModel()));
await tester.pumpWidget(MyApp(model: TestModel()));

// Verify that our counter starts at 0.
expect(find.text('111'), findsOneWidget);
Expand Down
4 changes: 2 additions & 2 deletions lib/scoped_model.dart
Expand Up @@ -78,7 +78,7 @@ class ModelFinder<T extends Model> {
///
/// [Widget]s who call [of] with a [rebuildOnChange] of true will be rebuilt
/// whenever there's a change to the returned model.
T of(BuildContext context, {bool rebuildOnChange: false}) {
T of(BuildContext context, {bool rebuildOnChange = false}) {
return ScopedModel.of<T>(context, rebuildOnChange: rebuildOnChange);
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ class ScopedModel<T extends Model> extends StatelessWidget {
: context.ancestorWidgetOfExactType(type);

if (widget == null) {
throw new ScopedModelError();
throw ScopedModelError();
} else {
return (widget as _InheritedModel<T>).model;
}
Expand Down
52 changes: 26 additions & 26 deletions test/scoped_model_test.dart
Expand Up @@ -6,8 +6,8 @@ void main() {
testWidgets('Models can be handed down from parent to child',
(WidgetTester tester) async {
final initialValue = 0;
final model = new TestModel(initialValue);
final widget = new TestWidget(model);
final model = TestModel(initialValue);
final widget = TestWidget(model);

await tester.pumpWidget(widget);

Expand All @@ -17,8 +17,8 @@ void main() {
testWidgets('Widgets update when the model notifies the listeners',
(WidgetTester tester) async {
final initialValue = 0;
final model = new TestModel(initialValue);
final widget = new TestWidget(model);
final model = TestModel(initialValue);
final widget = TestWidget(model);

// Starts out at the initial value
await tester.pumpWidget(widget);
Expand All @@ -37,8 +37,8 @@ void main() {
'Widgets do not update when the model notifies the listeners if the choose not to',
(WidgetTester tester) async {
final initialValue = 0;
final model = new TestModel(initialValue);
final widget = new TestWidget.noRebuild(model);
final model = TestModel(initialValue);
final widget = TestWidget.noRebuild(model);

// Starts out at the initial value
await tester.pumpWidget(widget);
Expand All @@ -55,21 +55,21 @@ void main() {

testWidgets("model change doesn't build widgets between model and descendant",
(WidgetTester tester) async {
var testModel = new TestModel();
var testModel = TestModel();

// use List to pass the counter by reference
List<int> buildCounter = [0];

// build widget tree with items between scope and descendant
var tree = new MaterialApp(
home: new ScopedModel<TestModel>(
var tree = MaterialApp(
home: ScopedModel<TestModel>(
model: testModel,
child: new Container(
child: new BuildCountContainer(
child: Container(
child: BuildCountContainer(
buildCounter: buildCounter,
child: new ScopedModelDescendant<TestModel>(
child: ScopedModelDescendant<TestModel>(
builder: (BuildContext context, Widget child, TestModel model) {
return new Text("${model.counter}");
return Text("${model.counter}");
},
),
),
Expand Down Expand Up @@ -98,8 +98,8 @@ void main() {
testWidgets('Throws an error if type info not provided',
(WidgetTester tester) async {
final initialValue = 0;
final model = new TestModel(initialValue);
final widget = new ErrorWidget(model);
final model = TestModel(initialValue);
final widget = ErrorWidget(model);

await tester.pumpWidget(widget);

Expand Down Expand Up @@ -128,19 +128,19 @@ class TestWidget extends StatelessWidget {

TestWidget(this.model, [this.rebuildOnChange = true]);

factory TestWidget.noRebuild(TestModel model) => new TestWidget(model, false);
factory TestWidget.noRebuild(TestModel model) => TestWidget(model, false);

@override
Widget build(BuildContext context) {
return new ScopedModel<TestModel>(
return ScopedModel<TestModel>(
model: model,
// Extra nesting to ensure the model is sent down the tree.
child: new Container(
child: new Container(
child: new ScopedModelDescendant<TestModel>(
child: Container(
child: Container(
child: ScopedModelDescendant<TestModel>(
rebuildOnChange: rebuildOnChange,
builder: (context, child, model) {
return new Text(
return Text(
model.counter.toString(),
textDirection: TextDirection.ltr,
);
Expand All @@ -160,15 +160,15 @@ class ErrorWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return new ScopedModel<TestModel>(
return ScopedModel<TestModel>(
model: model,
// Extra nesting to ensure the model is sent down the tree.
child: new Container(
child: new Container(
child: new ScopedModelDescendant(
child: Container(
child: Container(
child: ScopedModelDescendant(
rebuildOnChange: rebuildOnChange,
builder: (context, child, model) {
return new Text(
return Text(
model.counter.toString(),
textDirection: TextDirection.ltr,
);
Expand Down

0 comments on commit 10b8abd

Please sign in to comment.