Kate Lovett a04fb324be
Bump Dart to 3.8 and reformat (#171703)
Bumps the Dart version to 3.8 across the repo (excluding
engine/src/flutter/third_party) and applies formatting updates from Dart
3.8.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-07-07 17:58:32 +00:00

120 lines
3.7 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';
void main() {
// Changes made in https://github.com/flutter/flutter/pull/142151
MaterialState selected = MaterialState.selected;
MaterialState hovered = MaterialState.hovered;
MaterialState focused = MaterialState.focused;
MaterialState pressed = MaterialState.pressed;
MaterialState dragged = MaterialState.dragged;
MaterialState scrolledUnder = MaterialState.scrolledUnder;
MaterialState disabled = MaterialState.disabled;
MaterialState error = MaterialState.error;
final MaterialPropertyResolver<MouseCursor?> resolveCallback;
Color getColor(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
if (states.contains(MaterialState.selected)) {
return Color(0xFF000002);
}
return Color(0xFF000004);
}
if (states.contains(MaterialState.selected)) {
return Color(0xFF000001);
}
return Color(0xFF000003);
}
final MaterialStateProperty<Color> backgroundColor =
MaterialStateColor.resolveWith(getColor);
TextStyle floatingLabelStyle = MaterialStateTextStyle.resolveWith((
Set<MaterialState> states,
) {
final Color color = states.contains(MaterialState.error)
? Theme.of(context).colorScheme.error
: Colors.orange;
return TextStyle(color: color, letterSpacing: 1.3);
});
final MaterialStateProperty<Icon?> thumbIcon =
MaterialStateProperty.resolveWith<Icon?>((Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const Icon(Icons.check);
}
return const Icon(Icons.close);
});
final Color backgroundColor = MaterialStatePropertyAll<Color>(
Colors.blue.withOpacity(0.12),
);
final MaterialStatesController statesController = MaterialStatesController(
<MaterialState>{if (widget.selected) MaterialState.selected},
);
}
class _MouseCursor extends MaterialStateMouseCursor {
const _MouseCursor(this.resolveCallback);
final MaterialPropertyResolver<MouseCursor?> resolveCallback;
@override
MouseCursor resolve(Set<MaterialState> states) =>
resolveCallback(states) ?? MouseCursor.uncontrolled;
}
class SelectedBorder extends RoundedRectangleBorder
implements MaterialStateOutlinedBorder {
const SelectedBorder();
@override
OutlinedBorder? resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return const RoundedRectangleBorder();
}
return null;
}
}
class _MyWidget extends StatefulWidget {
const _MyWidget({
required this.controller,
required this.evaluator,
required this.materialState,
});
final bool Function(_MyWidgetState state) evaluator;
/// Stream passed down to the child [_InnerWidget] to begin the process.
/// This plays the role of an actual user interaction in the wild, but allows
/// us to engage the system without mocking pointers/hovers etc.
final StreamController<bool> controller;
/// The value we're watching in the given test.
final MaterialState materialState;
MaterialStateBorderSide? get side {
return MaterialStateBorderSide.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
if (states.contains(MaterialState.selected)) {
return const BorderSide(width: 2.0);
}
return BorderSide(width: 1.0);
}
if (states.contains(MaterialState.selected)) {
return const BorderSide(width: 1.5);
}
return BorderSide(width: 0.5);
});
}
@override
State createState() => _MyWidgetState();
}