Fix some issues with samples (#95044)

This commit is contained in:
Greg Spencer
2021-12-13 09:29:09 -08:00
committed by GitHub
parent 77d6e96083
commit bbc21fe3ed
10 changed files with 125 additions and 47 deletions

View File

@@ -0,0 +1,48 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for MouseCursor
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'MouseCursor Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: MouseRegion(
cursor: SystemMouseCursors.text,
child: Container(
width: 200,
height: 100,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.yellow),
),
),
),
);
}
}

View File

@@ -69,7 +69,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
),
const Text('Push to a new screen, then tap on shouldPop '
'button to toggle its value. Press the back '
'button in the appBar to check its behaviour '
'button in the appBar to check its behavior '
'for different values of shouldPop'),
],
),

View File

@@ -0,0 +1,21 @@
// Copyright 2014 The Flutter 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/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_api_samples/services/mouse_cursor/mouse_cursor.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Uses Text Cursor', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
expect(find.byType(MouseRegion), findsNWidgets(2)); // There's one in the MaterialApp
final Finder mouseRegionFinder = find.ancestor(of: find.byType(Container), matching: find.byType(MouseRegion));
expect(mouseRegionFinder, findsOneWidget);
expect((tester.widget(mouseRegionFinder) as MouseRegion).cursor, equals(SystemMouseCursors.text));
});
}

View File

@@ -0,0 +1,32 @@
// Copyright 2014 The Flutter 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_api_samples/widgets/will_pop_scope/will_pop_scope.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('pressing shouldPop button changes shouldPop', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
final Finder buttonFinder = find.text('shouldPop: true');
expect(buttonFinder, findsOneWidget);
await tester.tap(buttonFinder);
await tester.pump();
expect(find.text('shouldPop: false'), findsOneWidget);
});
testWidgets('pressing Push button pushes route', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
final Finder buttonFinder = find.text('Push');
expect(buttonFinder, findsOneWidget);
expect(find.byType(example.MyStatefulWidget), findsOneWidget);
await tester.tap(buttonFinder);
await tester.pumpAndSettle();
expect(find.byType(example.MyStatefulWidget, skipOffstage: false), findsNWidgets(2));
});
}