We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
可以参考Flutter源码,在类中给出一个copyWith的方法。(当然,方法名可以随意)
The text was updated successfully, but these errors were encountered:
比如MediaQueryData有非常多的属性,如果根据旧对象想得到只是一两条不同的新对象,一点点写会比较麻烦.
MediaQueryData
旧对象
新对象
const MediaQueryData({ this.size = Size.zero, this.devicePixelRatio = 1.0, this.textScaleFactor = 1.0, this.platformBrightness = Brightness.light, this.padding = EdgeInsets.zero, this.viewInsets = EdgeInsets.zero, this.systemGestureInsets = EdgeInsets.zero, this.viewPadding = EdgeInsets.zero, this.alwaysUse24HourFormat = false, this.accessibleNavigation = false, this.invertColors = false, this.highContrast = false, this.disableAnimations = false, this.boldText = false, this.navigationMode = NavigationMode.traditional, })
MediaQueryData源码中使用copyWith方便构建新对象。
copyWith
MediaQueryData copyWith({ Size size, double devicePixelRatio, double textScaleFactor, Brightness platformBrightness, EdgeInsets padding, EdgeInsets viewPadding, EdgeInsets viewInsets, EdgeInsets systemGestureInsets, bool alwaysUse24HourFormat, bool highContrast, bool disableAnimations, bool invertColors, bool accessibleNavigation, bool boldText, NavigationMode navigationMode, }) { return MediaQueryData( size: size ?? this.size, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, textScaleFactor: textScaleFactor ?? this.textScaleFactor, platformBrightness: platformBrightness ?? this.platformBrightness, padding: padding ?? this.padding, viewPadding: viewPadding ?? this.viewPadding, viewInsets: viewInsets ?? this.viewInsets, systemGestureInsets: systemGestureInsets ?? this.systemGestureInsets, alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, invertColors: invertColors ?? this.invertColors, highContrast: highContrast ?? this.highContrast, disableAnimations: disableAnimations ?? this.disableAnimations, accessibleNavigation: accessibleNavigation ?? this.accessibleNavigation, boldText: boldText ?? this.boldText, navigationMode: navigationMode ?? this.navigationMode, ); }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: