mirror of
https://github.com/flutter/flutter.git
synced 2026-02-15 15:23:32 +08:00
Rather than requiring the developer to specify a full Decoration, we now just take an ImageProvider for the thumb image. Also, fix ImageFit.scaleDown to actually work. Fixes #4571 Fixes #4673
75 lines
1.8 KiB
Dart
75 lines
1.8 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
class TestBoxPainter extends BoxPainter {
|
|
TestBoxPainter(VoidCallback onChanged): super(onChanged);
|
|
|
|
@override
|
|
void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) { }
|
|
}
|
|
|
|
class TestDecoration extends Decoration {
|
|
int listeners = 0;
|
|
|
|
@override
|
|
Decoration lerpFrom(Decoration a, double t) {
|
|
if (t == 0.0)
|
|
return a;
|
|
if (t == 1.0)
|
|
return this;
|
|
return new TestDecoration();
|
|
}
|
|
|
|
@override
|
|
Decoration lerpTo(Decoration b, double t) {
|
|
if (t == 1.0)
|
|
return b;
|
|
if (t == 0.0)
|
|
return this;
|
|
return new TestDecoration();
|
|
}
|
|
|
|
@override
|
|
BoxPainter createBoxPainter([VoidCallback onChanged]) {
|
|
if (onChanged != null)
|
|
listeners += 1;
|
|
return new TestBoxPainter(onChanged);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('Switch can toggle on tap', (WidgetTester tester) async {
|
|
Key switchKey = new UniqueKey();
|
|
bool value = false;
|
|
|
|
await tester.pumpWidget(
|
|
new StatefulBuilder(
|
|
builder: (BuildContext context, StateSetter setState) {
|
|
return new Material(
|
|
child: new Center(
|
|
child: new Switch(
|
|
key: switchKey,
|
|
value: value,
|
|
onChanged: (bool newValue) {
|
|
setState(() {
|
|
value = newValue;
|
|
});
|
|
}
|
|
)
|
|
)
|
|
);
|
|
}
|
|
)
|
|
);
|
|
|
|
expect(value, isFalse);
|
|
await tester.tap(find.byKey(switchKey));
|
|
expect(value, isTrue);
|
|
});
|
|
}
|