Skip to content

Commit

Permalink
Update deprecated members
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed May 16, 2024
1 parent eeef512 commit 6aec7ff
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 79 deletions.
16 changes: 4 additions & 12 deletions packages/dropdown_button2/lib/src/dropdown_button2.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: deprecated_member_use_from_same_package

/*
* Created by AHMED ELSAYED on 30 Nov 2021.
* email: [email protected]
Expand Down Expand Up @@ -669,14 +667,11 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
widget.onChanged != null;

Orientation _getOrientation(BuildContext context) {
// TODO(Ahmed): use maybeOrientationOf [flutter>=v3.10.0].
Orientation? result = MediaQuery.maybeOf(context)?.orientation;
Orientation? result = MediaQuery.maybeOrientationOf(context);
if (result == null) {
// If there's no MediaQuery, then use the window aspect to determine
// If there's no MediaQuery, then use the current FlutterView to determine
// orientation.
// TODO(Ahmed): use View.of(context) and update the comment [flutter>=v3.10.0].
// ignore: deprecated_member_use
final Size size = WidgetsBinding.instance.window.physicalSize;
final Size size = View.of(context).physicalSize;
result = size.width > size.height
? Orientation.landscape
: Orientation.portrait;
Expand Down Expand Up @@ -771,10 +766,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
alignment: widget.alignment,
children: buttonHeight != null
? buttonItems
.mapIndexed((item, index) => item)
.toList()
// TODO(Ahmed): use indexed from Flutter [Dart>=v3.0.0].
: buttonItems.mapIndexed((item, index) {
: buttonItems.map((item) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[item],
Expand Down
2 changes: 1 addition & 1 deletion packages/dropdown_button2/lib/src/dropdown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class _DropdownMenuPainter extends CustomPainter {
);

final Tween<double> bottom = Tween<double>(
begin: _clampDouble(top.begin! + itemHeight,
begin: clampDouble(top.begin! + itemHeight,
math.min(itemHeight, size.height), size.height),
end: size.height,
);
Expand Down
5 changes: 2 additions & 3 deletions packages/dropdown_button2/lib/src/dropdown_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
switch (FocusManager.instance.highlightMode) {
case FocusHighlightMode.touch:
inTraditionalMode = false;
// TODO(Ahmed): Remove decorative breaks and add lint to it [flutter>=v3.10.0].
break;
case FocusHighlightMode.traditional:
inTraditionalMode = true;
Expand Down Expand Up @@ -204,8 +203,8 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
final DropdownItem<T> dropdownItem = widget.route.items[widget.itemIndex];
final double unit = 0.5 / (widget.route.items.length + 1.5);
final double start =
_clampDouble(menuCurveEnd + (widget.itemIndex + 1) * unit, 0.0, 1.0);
final double end = _clampDouble(start + 1.5 * unit, 0.0, 1.0);
clampDouble(menuCurveEnd + (widget.itemIndex + 1) * unit, 0.0, 1.0);
final double end = clampDouble(start + 1.5 * unit, 0.0, 1.0);
final CurvedAnimation opacity = CurvedAnimation(
parent: widget.route.animation!, curve: Interval(start, end));

Expand Down
18 changes: 9 additions & 9 deletions packages/dropdown_button2/lib/src/dropdown_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
//Exclude BottomInset from maxHeight to avoid overlapping menu items
//with keyboard when using searchable dropdown.
//This will ensure menu is drawn in the actual available height.
// TODO(Ahmed): use paddingOf/paddingOf [flutter>=v3.10.0].
final MediaQueryData mediaQuery = MediaQuery.of(ctx);
final padding = MediaQuery.paddingOf(context);
final viewInsets = MediaQuery.viewInsetsOf(context);
final BoxConstraints actualConstraints = constraints.copyWith(
maxHeight: constraints.maxHeight - mediaQuery.viewInsets.bottom);
maxHeight: constraints.maxHeight - viewInsets.bottom);
final EdgeInsets mediaQueryPadding =
dropdownStyle.useSafeArea ? mediaQuery.padding : EdgeInsets.zero;
dropdownStyle.useSafeArea ? padding : EdgeInsets.zero;
return ValueListenableBuilder<Rect?>(
valueListenable: buttonRect,
builder: (BuildContext context, Rect? rect, _) {
Expand Down Expand Up @@ -367,14 +367,14 @@ class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate {
case DropdownDirection.textDirection:
switch (textDirection!) {
case TextDirection.rtl:
left = _clampDouble(
left = clampDouble(
buttonRect.right - childSize.width + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case TextDirection.ltr:
left = _clampDouble(
left = clampDouble(
buttonRect.left + offset.dx,
0.0,
size.width - childSize.width,
Expand All @@ -383,21 +383,21 @@ class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate {
}
break;
case DropdownDirection.right:
left = _clampDouble(
left = clampDouble(
buttonRect.left + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case DropdownDirection.left:
left = _clampDouble(
left = clampDouble(
buttonRect.right - childSize.width + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case DropdownDirection.center:
left = _clampDouble(
left = clampDouble(
(size.width - childSize.width) / 2 + offset.dx,
0.0,
size.width - childSize.width,
Expand Down
44 changes: 0 additions & 44 deletions packages/dropdown_button2/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
part of 'dropdown_button2.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.

/// Same as [num.clamp] but optimized for non-null [double].
///
/// This is faster because it avoids polymorphism, boxing, and special cases for
/// floating point numbers.
//
// See also: //dev/benchmarks/microbenchmarks/lib/foundation/clamp.dart
// TODO(Ahmed): use clampDouble from Flutter [flutter>=v3.3.0].
double _clampDouble(double x, double min, double max) {
assert(min <= max && !max.isNaN && !min.isNaN);
if (x < min) {
return min;
}
if (x > max) {
return max;
}
if (x.isNaN) {
return max;
}
return x;
}

/// Adds separators to a list of heights.
///
/// The [itemHeights] property is the list of heights of the items.
Expand Down Expand Up @@ -54,25 +29,6 @@ List<double> addSeparatorsHeights({
return heights;
}

// ignore: public_member_api_docs
extension ExtendedIterable<E> on Iterable<E> {
/// Like Iterable<T>.map but the callback has index as second argument
Iterable<T> mapIndexed<T>(T Function(E e, int i) f) {
var i = 0;
return map((e) => f(e, i++));
}

/// The last element of this iterable, or `null` if the iterable is empty.
///
// TODO(Ahmed): use lastOrNull from Flutter [Dart>=v3.0.0].
E? get lastOrNull {
if (isEmpty) {
return null;
}
return last;
}
}

void _uniqueValueAssert<T>(
List<DropdownItem<T>>? items,
ValueListenable<T?>? valueListenable,
Expand Down
14 changes: 4 additions & 10 deletions packages/dropdown_button2_test/test/utils/widget_tester_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: deprecated_member_use

part of 'utils.dart';

/// An extension that adds functions to a [WidgetTester] object.
Expand All @@ -13,15 +11,11 @@ extension WidgetTesterX on WidgetTester {

/// Configure the tester view to represent the given view variant.
void configureView(ViewVariant viewVariant) {
// TODO(Ahmed): use WidgetTester.view [flutter>=v3.10.0].
// view.physicalSize = viewVariant.physicalSize;
// view.devicePixelRatio = viewVariant.devicePixelRatio;

binding.window.physicalSizeTestValue = viewVariant.physicalSize;
binding.window.devicePixelRatioTestValue = viewVariant.devicePixelRatio;
view.physicalSize = viewVariant.physicalSize;
view.devicePixelRatio = viewVariant.devicePixelRatio;

addTearDown(binding.window.clearPhysicalSizeTestValue);
addTearDown(binding.window.clearDevicePixelRatioTestValue);
addTearDown(view.resetPhysicalSize);
addTearDown(view.resetDevicePixelRatio);
}

Future<void> verifyGolden(dynamic actual, Object file) async {
Expand Down

0 comments on commit 6aec7ff

Please sign in to comment.