mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This PR contributes to https://github.com/flutter/flutter/issues/155313 ### Description - Adds example for `WidgetStateProperty` - Adds tests for `examples/api/lib/widgets/widget_state/widget_state_property.0.dart`
49 lines
1.3 KiB
Dart
49 lines
1.3 KiB
Dart
// 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 [WidgetStateProperty].
|
|
|
|
void main() {
|
|
runApp(const WidgetStatePropertyExampleApp());
|
|
}
|
|
|
|
class WidgetStatePropertyExampleApp extends StatelessWidget {
|
|
const WidgetStatePropertyExampleApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
appBar: AppBar(title: const Text('WidgetStateProperty Sample')),
|
|
body: const Center(
|
|
child: WidgetStatePropertyExample(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class WidgetStatePropertyExample extends StatelessWidget {
|
|
const WidgetStatePropertyExample({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextButton(
|
|
style: ButtonStyle(
|
|
foregroundColor: WidgetStateProperty<Color>.fromMap(
|
|
<WidgetStatesConstraint, Color>{
|
|
WidgetState.focused: Colors.blueAccent,
|
|
WidgetState.pressed | WidgetState.hovered: Colors.blue,
|
|
WidgetState.any: Colors.red,
|
|
},
|
|
),
|
|
),
|
|
onPressed: () {},
|
|
child: const Text('TextButton'),
|
|
);
|
|
}
|
|
}
|