mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
82 lines
2.0 KiB
Dart
82 lines
2.0 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';
|
|
|
|
void main() {
|
|
testWidgets('Switch can toggle on tap', (WidgetTester tester) async {
|
|
final 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);
|
|
});
|
|
|
|
testWidgets('Switch can drag', (WidgetTester tester) async {
|
|
bool value = false;
|
|
|
|
await tester.pumpWidget(
|
|
new StatefulBuilder(
|
|
builder: (BuildContext context, StateSetter setState) {
|
|
return new Material(
|
|
child: new Center(
|
|
child: new Switch(
|
|
value: value,
|
|
onChanged: (bool newValue) {
|
|
setState(() {
|
|
value = newValue;
|
|
});
|
|
}
|
|
)
|
|
)
|
|
);
|
|
}
|
|
)
|
|
);
|
|
|
|
expect(value, isFalse);
|
|
|
|
await tester.drag(find.byType(Switch), const Offset(-30.0, 0.0));
|
|
|
|
expect(value, isFalse);
|
|
|
|
await tester.drag(find.byType(Switch), const Offset(30.0, 0.0));
|
|
|
|
expect(value, isTrue);
|
|
|
|
await tester.pump();
|
|
await tester.drag(find.byType(Switch), const Offset(30.0, 0.0));
|
|
|
|
expect(value, isTrue);
|
|
|
|
await tester.pump();
|
|
await tester.drag(find.byType(Switch), const Offset(-30.0, 0.0));
|
|
|
|
expect(value, isFalse);
|
|
});
|
|
}
|