Fix some issues with samples (#95044)
This commit is contained in:
48
examples/api/lib/services/mouse_cursor/mouse_cursor.0.dart
Normal file
48
examples/api/lib/services/mouse_cursor/mouse_cursor.0.dart
Normal 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),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
],
|
||||
),
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user