Skip to content

Commit

Permalink
Remove WidgetInspector due to breaking API change (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy authored Dec 23, 2024
1 parent db794e1 commit d670bd7
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 18 deletions.
33 changes: 33 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,36 @@
- Update wiredash-demo project for website
- Update latest SDK version in `console`
- Announce release on Twitter 🎉


## Handling deprecations of the Flutter SDK and dependencies

The Wiredash SDK strives to be compatible with all `stable` [Flutter releases](https://docs.flutter.dev/release/archive) within the last year as well as the current `master` channel.
To achieve this, we go the extra mile and work around breaking API changes or contribute fixes directly to the Flutter SDK to ensure compatibility.

The goal is to always have a single commit, being compatible with all versions.
This way we can make sure to deliver the latest features and bug fixes to all of our users.

These are the current deprecated APIs the Wiredash SDK is currently using as long as the deprecated APIs are not removed (usually after 12 months).

### Flutter v3.28 / Dart 3.6.0

- New `WidgetInspector` constructor https://github.com/flutter/flutter/pull/158219

### Flutter 3.27 / Dart 3.6.0

Multiple `Color` API changes
- https://docs.flutter.dev/release/breaking-changes/wide-gamut-framework
- https://github.com/flutter/engine/pull/54737

- `Color.alpha` -> `Color.a`
- `Color.red` -> `Color.r`
- `Color.green` -> `Color.g`
- `Color.blue` -> `Color.b`
- `Color.withOpacity()` -> `Color.withValues()`
- `Color.value` -> ?

### Flutter 3.10 / Dart 3.0.0

- `Iterable<T?>.whereNotNull()` -> `Iterable<T>.nonNulls` (Caused by pinned [`collection: 1.19.0`](https://pub.dev/packages/collection/changelog#1190) package)
- `MediaQuery.fromWindow` -> `MediaQuery.fromView` (deprecated in Flutter v3.7.0-32.0.pre) https://github.com/flutter/flutter/pull/119647
22 changes: 22 additions & 0 deletions examples/theme_editor/lib/marianos_clones/netflix_clone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ class _InitScreenState extends State<InitScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Colors.black.withOpacity(0.8),
// ignore: deprecated_member_use
Colors.black.withOpacity(0.42),
// ignore: deprecated_member_use
Colors.black.withOpacity(0.9),
],
begin: Alignment.topCenter,
Expand Down Expand Up @@ -910,8 +913,11 @@ class _LoginScreenState extends State<LoginScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Colors.black.withOpacity(0.8),
// ignore: deprecated_member_use
Colors.black.withOpacity(0.42),
// ignore: deprecated_member_use
Colors.black.withOpacity(0.9),
],
begin: Alignment.topCenter,
Expand All @@ -938,6 +944,7 @@ class _LoginScreenState extends State<LoginScreen> {
Container(
width: 450,
height: 675,
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.8),
padding: EdgeInsets.symmetric(
horizontal: breakpoint(size.width, 60, 40, 30),
Expand Down Expand Up @@ -1090,6 +1097,7 @@ class _LoginScreenState extends State<LoginScreen> {
SizedBox(height: 100),
Container(
width: size.width,
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.5),
height: 240,
child: Column(
Expand Down Expand Up @@ -1156,6 +1164,7 @@ class _LoginScreenState extends State<LoginScreen> {
height: 60,
width: 140,
decoration: BoxDecoration(
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.8),
border: Border.all(color: Color(0xFF333333), width: 2),
),
Expand Down Expand Up @@ -1202,6 +1211,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Colors.black.withOpacity(0.8),
Colors.transparent,
],
Expand Down Expand Up @@ -1936,7 +1946,9 @@ class _BrowseScreenState extends State<BrowseScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Color(0xFF060606).withOpacity(_fadePercentage),
// ignore: deprecated_member_use
Color(0xFF141414).withOpacity(_fadePercentage),
],
begin: Alignment.topCenter,
Expand Down Expand Up @@ -1994,7 +2006,9 @@ class _BrowseScreenState extends State<BrowseScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Color(0xFF060606).withOpacity(0.8),
// ignore: deprecated_member_use
Color(0xFF141414).withOpacity(0.0),
],
begin: Alignment.topCenter,
Expand All @@ -2012,7 +2026,9 @@ class _BrowseScreenState extends State<BrowseScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Color(0xFF060606).withOpacity(_fadePercentage),
// ignore: deprecated_member_use
Color(0xFF141414).withOpacity(_fadePercentage),
],
begin: Alignment.topCenter,
Expand Down Expand Up @@ -2135,6 +2151,7 @@ class _BrowseScreenState extends State<BrowseScreen> {
height: 150,
decoration: BoxDecoration(
gradient: LinearGradient(
// ignore: deprecated_member_use
colors: [Color(0xFF141414).withOpacity(0), Color(0xFF141414)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
Expand Down Expand Up @@ -2253,6 +2270,7 @@ class _BrowseScreenState extends State<BrowseScreen> {
height: 150,
decoration: BoxDecoration(
gradient: LinearGradient(
// ignore: deprecated_member_use
colors: [Color(0xFF141414).withOpacity(0), Color(0xFF141414)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
Expand Down Expand Up @@ -2770,10 +2788,12 @@ class NetflixPainter extends CustomPainter {
..lineTo(legWidth + 70, 0)
..close();
final shadowPaint = Paint()
// ignore: deprecated_member_use
..color = Colors.black.withOpacity(anim.middleLegOpacity)
..maskFilter = MaskFilter.blur(BlurStyle.normal, 30);
final middleLegPaint = Paint()
..color =
// ignore: deprecated_member_use
NetflixColors.netflixDarkRed.withOpacity(anim.middleLegOpacity);
canvas.clipRect(middleLegClipPath);
canvas.drawPath(shadowPath, shadowPaint);
Expand Down Expand Up @@ -2860,6 +2880,7 @@ class NetflixPainter extends CustomPainter {
canvas.save();
if (anim.leftLegOpacity > 0) {
final leftLegPaint = Paint()
// ignore: deprecated_member_use
..color = NetflixColors.netflixDarkRed.withOpacity(anim.leftLegOpacity);

canvas.drawRect(
Expand All @@ -2883,6 +2904,7 @@ class NetflixPainter extends CustomPainter {
rect,
Paint()
..color = rainbowColors[i % rainbowColors.length]!
// ignore: deprecated_member_use
.withOpacity(1.0 - anim.leftLegOpacity)
..maskFilter = MaskFilter.blur(BlurStyle.normal, 3),
);
Expand Down
12 changes: 12 additions & 0 deletions examples/theme_editor/lib/marianos_clones/whatsapp_clone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ class ContactItem extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.6),
),
),
Expand Down Expand Up @@ -1037,9 +1038,11 @@ class _ChatItemState extends State<ChatItem> {
color: _lastMessageMine(
widget.conversation,
)
// ignore: deprecated_member_use
? Colors.black.withOpacity(0.6)
: _countUnread(widget.conversation) > 0
? Colors.black
// ignore: deprecated_member_use
: Colors.black.withOpacity(0.6),
),
),
Expand Down Expand Up @@ -1779,12 +1782,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
SizedBox(height: 15),
Text(
'Your Name',
// ignore: deprecated_member_use
style: TextStyle(color: Colors.black.withOpacity(0.5)),
),
SizedBox(height: 20),
Text(
widget.user.name,
style: TextStyle(
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.8),
fontSize: 18,
),
Expand All @@ -1803,6 +1808,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
child: Text(
'This is not your username or pin. This name will be visible to your WhatsApp contacts.',
// ignore: deprecated_member_use
style: TextStyle(color: Colors.black.withOpacity(0.5)),
),
),
Expand All @@ -1817,12 +1823,14 @@ class _ProfileScreenState extends State<ProfileScreen> {
SizedBox(height: 15),
Text(
'About',
// ignore: deprecated_member_use
style: TextStyle(color: Colors.black.withOpacity(0.5)),
),
SizedBox(height: 20),
Text(
widget.user.status,
style: TextStyle(
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.8),
fontSize: 18,
),
Expand Down Expand Up @@ -2037,7 +2045,9 @@ class ContactScreenState extends State<ContactScreen> {
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
// ignore: deprecated_member_use
Colors.black.withOpacity(0.0),
// ignore: deprecated_member_use
Colors.black.withOpacity(0.8)
],
begin: Alignment.topCenter,
Expand Down Expand Up @@ -2170,13 +2180,15 @@ class ContactScreenState extends State<ContactScreen> {
Text(
'About and phone number',
style: TextStyle(
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.5),
),
),
SizedBox(height: 15),
Text(
_user!.status,
style: TextStyle(
// ignore: deprecated_member_use
color: Colors.black.withOpacity(0.8),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
2 changes: 2 additions & 0 deletions lib/src/core/network/api_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ extension WiredashApiWarnings on Response {
return warnings
.whereType<Map>()
.map((w) => WiredashApiWarning.tryParse(w))
// Switch to .nonNulls when minSdk is Dart 3.0
// ignore: deprecated_member_use
.whereNotNull()
.toList();
} catch (_) {
Expand Down
63 changes: 48 additions & 15 deletions lib/src/core/support/not_a_widgets_app.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ignore_for_file: join_return_with_assignment

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

/// Wrapper with default that most widgets required that are now wrapped by a
Expand Down Expand Up @@ -30,20 +29,54 @@ class _NotAWidgetsAppState extends State<NotAWidgetsApp> {
child: widget.child,
);

// Allow inspection of widgets
// ignore: deprecated_member_use
if (kDebugMode && WidgetsApp.debugShowWidgetInspectorOverride) {
child = WidgetInspector(
selectButtonBuilder: (BuildContext context, void Function() onPressed) {
return FloatingActionButton(
onPressed: onPressed,
mini: true,
child: const Icon(Icons.search),
);
},
child: child,
);
}
// Allow inspection of widgets, use to debug layout issues
// Not part of the codebase since https://github.com/flutter/flutter/pull/158219 introduced a breaking API change.
// Re-enable when we drop support for Flutter v3.27.0
// if (kDebugMode && WidgetsApp.debugShowWidgetInspectorOverride) {
// child = WidgetInspector(
// exitWidgetSelectionButtonBuilder: (
// BuildContext context, {
// required VoidCallback onPressed,
// required GlobalKey key,
// }) {
// final ThemeData theme = Theme.of(context);
// return FloatingActionButton(
// key: key,
// onPressed: onPressed,
// mini: true,
// backgroundColor: theme.colorScheme.onPrimaryContainer,
// foregroundColor: theme.colorScheme.primaryContainer,
// child: const Icon(
// Icons.close,
// semanticLabel: 'Exit Select Widget mode.',
// ),
// );
// },
// moveExitWidgetSelectionButtonBuilder: (
// BuildContext context, {
// required VoidCallback onPressed,
// bool isLeftAligned = true,
// }) {
// final ThemeData theme = Theme.of(context);
// return IconButton(
// color: theme.colorScheme.onPrimaryContainer,
// padding: EdgeInsets.zero,
// iconSize: 32,
// onPressed: onPressed,
// constraints: const BoxConstraints(
// minWidth: 40,
// minHeight: 40,
// ),
// icon: Icon(
// isLeftAligned ? Icons.arrow_right : Icons.arrow_left,
// semanticLabel:
// 'Move "Exit Select Widget mode" button to the ${isLeftAligned ? 'right' : 'left'}.',
// ),
// );
// },
// child: child,
// );
// }

// Any Text requires a directionality
child = Directionality(
Expand Down
2 changes: 2 additions & 0 deletions lib/src/core/theme/color_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ extension ColorBrightness on Color {
}

Brightness get brightness {
// Changed in Flutter 3.26 https://github.com/flutter/engine/pull/54737
// ignore: deprecated_member_use
final grayscale = (0.299 * red) + (0.587 * green) + (0.114 * blue);

if (grayscale > 128) {
Expand Down
Loading

0 comments on commit d670bd7

Please sign in to comment.