-
Notifications
You must be signed in to change notification settings - Fork 1
/
MediaQuery.dart
95 lines (90 loc) · 2.82 KB
/
MediaQuery.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:flutter/material.dart';
void main() => runApp(const MediaQueryApp());
class MediaQueryApp extends StatefulWidget {
const MediaQueryApp({super.key});
@override
State<MediaQueryApp> createState() => _MediaQueryAppState();
}
class _MediaQueryAppState extends State<MediaQueryApp> {
bool isDark = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: isDark ? ThemeData.dark() : ThemeData.light(),
home: Scaffold(
appBar: AppBar(
title: const Center(child: Text("MediaQuery App")),
actions: <Widget>[
Center(
child: Text(
isDark ? "LIGHT" : "DARK",
style: TextStyle(
fontSize: 20,
color: isDark ? Colors.amberAccent : Colors.black),
),
),
const SizedBox(width: 15),
Switch(
value: isDark,
activeColor: Colors.amber,
onChanged: (bool value) {
setState(() {
isDark = !isDark;
});
}),
],
),
body: const Center(child: TemplateClass()),
),
);
}
}
class TemplateClass extends StatefulWidget {
const TemplateClass({super.key});
@override
State<TemplateClass> createState() => _TemplateClassState();
}
class _TemplateClassState extends State<TemplateClass> {
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Container(
padding: const EdgeInsets.all(10),
child: GridView.count(
mainAxisSpacing: 5,
crossAxisSpacing: 5,
crossAxisCount: 2,
children: <Container>[
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1, color: Theme.of(context).colorScheme.secondary),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text("The size is: $size"),
)),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1, color: Theme.of(context).colorScheme.secondary),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text("The size is: $size"),
)),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1, color: Theme.of(context).colorScheme.secondary),
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text("The size is: $size"),
)),
],
),
);
}
}