home_page.dart
3.92 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2019 The FlutterCandies author. All rights reserved.
// Use of this source code is governed by an Apache license that can be found
// in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart';
import '../constants/extensions.dart';
import '../customs/custom_picker_page.dart';
import '../main.dart';
import 'multi_assets_page.dart';
import 'single_assets_page.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final PageController controller = PageController();
int currentIndex = 0;
@override
void initState() {
super.initState();
controller.addListener(pageControllerListener);
}
void selectIndex(int index) {
if (index == currentIndex) {
return;
}
controller.animateToPage(
index,
duration: kThemeAnimationDuration,
curve: Curves.easeInOut,
);
}
void pageControllerListener() {
final int? currentPage = controller.page?.round();
if (currentPage != null && currentPage != currentIndex) {
currentIndex = currentPage;
if (mounted) {
setState(() {});
}
}
}
Widget header(BuildContext context) {
return Container(
margin: const EdgeInsetsDirectional.only(top: 30.0),
height: 60.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AspectRatio(
aspectRatio: 1.0,
child: Hero(
tag: 'LOGO',
child: Image.asset('assets/flutter_candies_logo.png'),
),
),
const SizedBox(width: 10.0),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Semantics(
sortKey: const OrdinalSortKey(0),
child: Text(
context.l10n.appTitle,
style: Theme.of(context).textTheme.titleLarge,
),
),
Semantics(
sortKey: const OrdinalSortKey(0.1),
child: Text(
context.l10n.appVersion(
packageVersion ?? context.l10n.appVersionUnknown,
),
style: Theme.of(context).textTheme.bodySmall,
),
),
],
),
const SizedBox(width: 20.0),
],
),
);
}
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: Theme.of(context).brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark,
child: Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
header(context),
Expanded(
child: PageView(
controller: controller,
children: const <Widget>[
MultiAssetsPage(),
SingleAssetPage(),
CustomPickersPage(),
],
),
),
],
),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
onTap: selectIndex,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: const Icon(Icons.photo_library),
label: context.l10n.navMulti,
),
BottomNavigationBarItem(
icon: const Icon(Icons.photo),
label: context.l10n.navSingle,
),
BottomNavigationBarItem(
icon: const Icon(Icons.explore),
label: context.l10n.navCustom,
),
],
),
),
);
}
}