mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-03-15 04:23:17 +08:00
Add compatibility helpers for Flutter API differences and update color opacity methods
This commit is contained in:
@@ -20,6 +20,9 @@ import 'package:proxypin/ui/configuration.dart';
|
||||
import 'package:proxypin/ui/desktop/preference.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
// Compat helpers (withValues extension)
|
||||
import 'package:proxypin/utils/flutter_compat.dart';
|
||||
|
||||
///左侧导航栏
|
||||
/// @author wanghongen
|
||||
/// 2024/8/6
|
||||
|
||||
@@ -15,6 +15,9 @@ import 'package:proxypin/ui/component/widgets.dart';
|
||||
import '../../component/app_dialog.dart' show CustomToast;
|
||||
import '../../component/http_method_popup.dart';
|
||||
|
||||
// Compat helpers (withValues extension)
|
||||
import 'package:proxypin/utils/flutter_compat.dart';
|
||||
|
||||
class RequestBreakpointPage extends StatefulWidget {
|
||||
final int? windowId;
|
||||
|
||||
@@ -215,7 +218,7 @@ class _RequestBreakpointPageState extends State<RequestBreakpointPage> {
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.grey.withValues(alpha: 0.2))),
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.grey.withOpacity(0.2))),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
@@ -249,7 +252,7 @@ class _RequestBreakpointPageState extends State<RequestBreakpointPage> {
|
||||
return InkWell(
|
||||
highlightColor: Colors.transparent,
|
||||
splashColor: Colors.transparent,
|
||||
hoverColor: primaryColor.withValues(alpha: 0.3),
|
||||
hoverColor: primaryColor.withOpacity(0.3),
|
||||
onDoubleTap: () => _editRule(rule: rule),
|
||||
onSecondaryTapDown: (details) => _showMenu(details.globalPosition, index: index),
|
||||
onHover: (hover) {
|
||||
@@ -275,9 +278,9 @@ class _RequestBreakpointPageState extends State<RequestBreakpointPage> {
|
||||
},
|
||||
child: Container(
|
||||
color: selected.contains(index)
|
||||
? primaryColor.withValues(alpha: 0.5)
|
||||
? primaryColor.withOpacity(0.5)
|
||||
: index.isEven
|
||||
? Colors.grey.withValues(alpha: 0.1)
|
||||
? Colors.grey.withOpacity(0.1)
|
||||
: null,
|
||||
height: 32,
|
||||
padding: const EdgeInsets.all(5),
|
||||
|
||||
@@ -44,6 +44,9 @@ import '../../component/widgets.dart';
|
||||
import '../setting/proxy.dart';
|
||||
import '../setting/request_map.dart';
|
||||
|
||||
// Add compatibility helpers (withValues extension, BuildContext.colorScheme)
|
||||
import 'package:proxypin/utils/flutter_compat.dart';
|
||||
|
||||
/// @author wanghongen
|
||||
/// 2024/9/30
|
||||
class ConfigPage extends StatefulWidget {
|
||||
@@ -159,7 +162,7 @@ class _ConfigPageState extends State<ConfigPage> {
|
||||
leading: Icon(Icons.javascript_outlined, color: color),
|
||||
trailing: arrow,
|
||||
onTap: () => navigator(context, const MobileScript())),
|
||||
Divider(height: 0, thickness: 0.3, color: Theme.of(context).dividerColor.withOpacity(alpha: 0.22)),
|
||||
Divider(height: 0, thickness: 0.3, color: Theme.of(context).dividerColor.withOpacity(0.22)),
|
||||
ListTile(
|
||||
title: Text(localizations.breakpoint),
|
||||
leading: Icon(Icons.bug_report_outlined, color: color),
|
||||
@@ -236,7 +239,7 @@ class SettingPage extends StatelessWidget {
|
||||
proxyServer: proxyServer,
|
||||
title: '${localizations.proxy}${isEn ? ' ' : ''}${localizations.port}',
|
||||
textStyle: const TextStyle(fontSize: 16)),
|
||||
Divider(height: 0, thickness: 0.3, color: Theme.of(context).dividerColor.withOpacity(alpha: 0.22)),
|
||||
Divider(height: 0, thickness: 0.3, color: Theme.of(context).dividerColor.withOpacity(0.22)),
|
||||
if (Platform.isAndroid)
|
||||
ListTile(
|
||||
title: Text(localizations.systemProxy),
|
||||
|
||||
@@ -41,6 +41,9 @@ import 'package:proxypin/ui/mobile/setting/ssl.dart';
|
||||
import 'package:proxypin/ui/mobile/widgets/about.dart';
|
||||
import 'package:proxypin/utils/listenable_list.dart';
|
||||
|
||||
// Compat helpers (withValues extension)
|
||||
import 'package:proxypin/utils/flutter_compat.dart';
|
||||
|
||||
import '../../component/proxy_port_setting.dart';
|
||||
import '../../component/widgets.dart';
|
||||
import '../../desktop/setting/external_proxy.dart';
|
||||
|
||||
@@ -11,6 +11,9 @@ import 'package:proxypin/network/http/http.dart';
|
||||
import 'package:proxypin/network/util/logger.dart';
|
||||
import 'package:proxypin/ui/component/widgets.dart';
|
||||
|
||||
// Compat helpers (withValues extension)
|
||||
import 'package:proxypin/utils/flutter_compat.dart';
|
||||
|
||||
import '../../component/http_method_popup.dart';
|
||||
|
||||
class MobileRequestBreakpointPage extends StatefulWidget {
|
||||
|
||||
33
lib/utils/flutter_compat.dart
Normal file
33
lib/utils/flutter_compat.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Compatibility helpers for small Flutter API differences used in this project.
|
||||
///
|
||||
/// Provides:
|
||||
/// - Color/MaterialColor.withValues({double? alpha, Map<int, Color>? values})
|
||||
/// to emulate older/newer helper methods used in the codebase.
|
||||
/// - BuildContext.colorScheme getter as a convenience.
|
||||
|
||||
extension ColorWithValues on Color {
|
||||
/// If [alpha] is provided, return this color with that opacity.
|
||||
/// If [values] is provided, return a MaterialColor constructed from this color value.
|
||||
/// Otherwise return `this`.
|
||||
Color withValues({double? alpha, Map<int, Color>? values}) {
|
||||
if (alpha != null) return withOpacity(alpha);
|
||||
if (values != null) return MaterialColor(value, values);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
extension MaterialColorWithValues on MaterialColor {
|
||||
/// Mirror above semantics for MaterialColor.
|
||||
Color withValues({double? alpha, Map<int, Color>? values}) {
|
||||
if (values != null) return MaterialColor(this.value, values);
|
||||
if (alpha != null) return Color(this.value).withOpacity(alpha);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
extension BuildContextColorScheme on BuildContext {
|
||||
ColorScheme get colorScheme => Theme.of(this).colorScheme;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user