Add WidgetStateMouseCursor example and tests for it. (#155552)
Fixes https://github.com/flutter/flutter/issues/155551 ### Description - Adds example for `WidgetStateMouseCursor` - Adds tests for `examples/api/lib/widgets/widget_state/widget_state_mouse_cursor.0.dart`
This commit is contained in:
committed by
GitHub
parent
3aae560735
commit
591cc39c2d
@@ -0,0 +1,85 @@
|
||||
// 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/material.dart';
|
||||
|
||||
/// Flutter code sample for [WidgetStateMouseCursor].
|
||||
|
||||
void main() {
|
||||
runApp(const WidgetStateMouseCursorExampleApp());
|
||||
}
|
||||
|
||||
class WidgetStateMouseCursorExampleApp extends StatelessWidget {
|
||||
const WidgetStateMouseCursorExampleApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('WidgetStateMouseCursor Sample')),
|
||||
body: const WidgetStateMouseCursorExample(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ListTileCursor extends WidgetStateMouseCursor {
|
||||
const ListTileCursor();
|
||||
|
||||
@override
|
||||
MouseCursor resolve(Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.disabled)) {
|
||||
return SystemMouseCursors.forbidden;
|
||||
}
|
||||
|
||||
return SystemMouseCursors.click;
|
||||
}
|
||||
|
||||
@override
|
||||
String get debugDescription => 'ListTileCursor()';
|
||||
}
|
||||
|
||||
class WidgetStateMouseCursorExample extends StatefulWidget {
|
||||
const WidgetStateMouseCursorExample({super.key});
|
||||
|
||||
@override
|
||||
State<WidgetStateMouseCursorExample> createState() => _WidgetStateMouseCursorExampleState();
|
||||
}
|
||||
|
||||
class _WidgetStateMouseCursorExampleState extends State<WidgetStateMouseCursorExample> {
|
||||
bool _enabled = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: const Text('ListTile'),
|
||||
enabled: _enabled,
|
||||
onTap: () {},
|
||||
mouseCursor: const ListTileCursor(),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'Enabled: ',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
Switch(
|
||||
value: _enabled,
|
||||
onChanged: (_) {
|
||||
setState(() {
|
||||
_enabled = !_enabled;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user