mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
[compass_app] Don't expose Dimens subclasses (#2541)
Avoid exposing the subclasses as they shouldn't be instantiated again or overridden. Also consistently use fields and getters in the declarations.
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
sealed class Dimens {
|
abstract final class Dimens {
|
||||||
const Dimens();
|
const Dimens();
|
||||||
|
|
||||||
/// General horizontal padding used to separate UI items
|
/// General horizontal padding used to separate UI items
|
||||||
@@ -14,10 +14,12 @@ sealed class Dimens {
|
|||||||
static const paddingVertical = 24.0;
|
static const paddingVertical = 24.0;
|
||||||
|
|
||||||
/// Horizontal padding for screen edges
|
/// Horizontal padding for screen edges
|
||||||
abstract final double paddingScreenHorizontal;
|
double get paddingScreenHorizontal;
|
||||||
|
|
||||||
/// Vertical padding for screen edges
|
/// Vertical padding for screen edges
|
||||||
abstract final double paddingScreenVertical;
|
double get paddingScreenVertical;
|
||||||
|
|
||||||
|
double get profilePictureSize;
|
||||||
|
|
||||||
/// Horizontal symmetric padding for screen edges
|
/// Horizontal symmetric padding for screen edges
|
||||||
EdgeInsets get edgeInsetsScreenHorizontal =>
|
EdgeInsets get edgeInsetsScreenHorizontal =>
|
||||||
@@ -27,39 +29,37 @@ sealed class Dimens {
|
|||||||
EdgeInsets get edgeInsetsScreenSymmetric => EdgeInsets.symmetric(
|
EdgeInsets get edgeInsetsScreenSymmetric => EdgeInsets.symmetric(
|
||||||
horizontal: paddingScreenHorizontal, vertical: paddingScreenVertical);
|
horizontal: paddingScreenHorizontal, vertical: paddingScreenVertical);
|
||||||
|
|
||||||
static final dimensDesktop = DimensDesktop();
|
static final Dimens desktop = _DimensDesktop();
|
||||||
static final dimensMobile = DimensMobile();
|
static final Dimens mobile = _DimensMobile();
|
||||||
|
|
||||||
/// Get dimensions definition based on screen size
|
/// Get dimensions definition based on screen size
|
||||||
factory Dimens.of(BuildContext context) =>
|
factory Dimens.of(BuildContext context) =>
|
||||||
switch (MediaQuery.sizeOf(context).width) {
|
switch (MediaQuery.sizeOf(context).width) {
|
||||||
> 600 => dimensDesktop,
|
> 600 => desktop,
|
||||||
_ => dimensMobile,
|
_ => mobile,
|
||||||
};
|
};
|
||||||
|
|
||||||
abstract final double profilePictureSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mobile dimensions
|
/// Mobile dimensions
|
||||||
class DimensMobile extends Dimens {
|
final class _DimensMobile extends Dimens {
|
||||||
@override
|
@override
|
||||||
double paddingScreenHorizontal = Dimens.paddingHorizontal;
|
final double paddingScreenHorizontal = Dimens.paddingHorizontal;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double paddingScreenVertical = Dimens.paddingVertical;
|
final double paddingScreenVertical = Dimens.paddingVertical;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double get profilePictureSize => 64.0;
|
final double profilePictureSize = 64.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Desktop/Web dimensions
|
/// Desktop/Web dimensions
|
||||||
class DimensDesktop extends Dimens {
|
final class _DimensDesktop extends Dimens {
|
||||||
@override
|
@override
|
||||||
double paddingScreenHorizontal = 100.0;
|
final double paddingScreenHorizontal = 100.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double paddingScreenVertical = 64.0;
|
final double paddingScreenVertical = 64.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double get profilePictureSize => 128.0;
|
final double profilePictureSize = 128.0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class _AppSearchBar extends StatelessWidget {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
top: Dimens.of(context).paddingScreenVertical,
|
top: Dimens.of(context).paddingScreenVertical,
|
||||||
bottom: Dimens.dimensMobile.paddingScreenVertical,
|
bottom: Dimens.mobile.paddingScreenVertical,
|
||||||
),
|
),
|
||||||
child: AppSearchBar(
|
child: AppSearchBar(
|
||||||
config: widget.viewModel.config,
|
config: widget.viewModel.config,
|
||||||
|
|||||||
Reference in New Issue
Block a user