-
Notifications
You must be signed in to change notification settings - Fork 71
/
size_config.dart
66 lines (56 loc) · 1.72 KB
/
size_config.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import 'package:flutter/material.dart';
// SizeConfig help us to make our UI responsive
/// Make sure you need to call [SizeConfig.init(context)] on your starting screen
class SizeConfig {
static MediaQueryData _mediaQueryData;
static double screenWidth;
static double screenHeight;
static double defaultSize;
static Orientation orientation;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
orientation = _mediaQueryData.orientation;
}
}
// Get the proportionate height as per screen size
double getProportionateScreenHeight(double inputHeight) {
double screenHeight = SizeConfig.screenHeight;
// Our designer use iPhone 11, that's why we use 896.0
return (inputHeight / 896.0) * screenHeight;
}
// Get the proportionate height as per screen size
double getProportionateScreenWidth(double inputWidth) {
double screenWidth = SizeConfig.screenWidth;
// 414 is the layout width that designer use or you can say iPhone 11 width
return (inputWidth / 414.0) * screenWidth;
}
// For add free space vertically
class VerticalSpacing extends StatelessWidget {
const VerticalSpacing({
Key key,
this.of = 20,
}) : super(key: key);
final double of;
@override
Widget build(BuildContext context) {
return SizedBox(
height: getProportionateScreenWidth(of),
);
}
}
// For add free space horizontally
class HorizontalSpacing extends StatelessWidget {
const HorizontalSpacing({
Key key,
this.of = 20,
}) : super(key: key);
final double of;
@override
Widget build(BuildContext context) {
return SizedBox(
width: getProportionateScreenWidth(of),
);
}
}