-
Notifications
You must be signed in to change notification settings - Fork 0
/
cupertino_example.dart
86 lines (82 loc) · 2.86 KB
/
cupertino_example.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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:appearance/appearance.dart';
class CupertinoHomePage extends StatefulWidget {
const CupertinoHomePage({
super.key,
});
@override
State<CupertinoHomePage> createState() => _CupertinoHomePageState();
}
class _CupertinoHomePageState extends State<CupertinoHomePage>
with AppearanceState {
@override
Widget build(BuildContext context) {
return BuildWithAppearance(
// initial => optional parameter, default value is [ThemeMode.system]
initial: ThemeMode.dark,
builder: (context) {
return CupertinoApp(
title: 'Appearance Demo',
theme: CupertinoThemeData(
brightness: Appearance.of(context)?.cupertinoBrightness!,
),
localizationsDelegates: const [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
home: cupertinoScaffold('Appearance (Cupertino Example)'),
);
},
);
}
Widget cupertinoScaffold(String title) {
final appearance = Appearance.of(context);
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text(title),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Spacer(flex: 2),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoButton.filled(
onPressed: () => appearance?.setMode(ThemeMode.light),
// disabledColor:
// appearance?.cupertinoBrightness == Brightness.dark
// ? Theme.of(context).colorScheme.primary
// : Colors.white,
child: const Icon(CupertinoIcons.sun_min),
),
const SizedBox(width: 22),
CupertinoButton.filled(
onPressed: () => appearance?.setMode(ThemeMode.dark),
// color: appearance?.cupertinoBrightness == Brightness.light
// ? Theme.of(context).colorScheme.primary
// : Colors.white,
child: const Icon(CupertinoIcons.moon),
),
],
),
const SizedBox(height: 18),
Text('Active theme is ${appearance?.mode.name}'),
const Spacer(flex: 2),
Align(
alignment: Alignment.bottomCenter,
child: CupertinoButton(
onPressed: () => Navigator.pop(context),
child: const Text('Show Material Example'),
),
),
const SizedBox(height: 22),
],
),
),
);
}
}