Skip to content

Commit 6052d23

Browse files
committed
separate the project to modules
1 parent 8da8182 commit 6052d23

File tree

74 files changed

+2305
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2305
-0
lines changed

flutter_clock_helper/.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 9bd02a1787bd264fde13a445a900ca28d08e3cef
8+
channel: master
9+
10+
project_type: package

flutter_clock_helper/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.0.1] - TODO: Add release date.
2+
3+
* TODO: Describe initial release.

flutter_clock_helper/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Flutter Clock Helper
2+
3+
This package provides scaffolding code for the clock in the Flutter Clock contest.
4+
5+
Contestants: Do not edit this code.
6+
7+
8+
## Model
9+
Provides data that can change in the clock. Look in model.dart for more details.
10+
11+
* Time format (12- or 24-hour)
12+
* Location
13+
* Temperature
14+
* Temperature high
15+
* Temperature low
16+
* Temperature unit
17+
* Weather unit
18+
19+
20+
## Clock Customizer
21+
Provides customizations for your clock (based on the model).
22+
You can change the behavior of your clock based on these customizations.
23+
24+
<img src='customizer.png' width='350'>
25+
26+
To use inside your app's `main.dart`:
27+
28+
```
29+
runApp(ClockCustomizer((ClockModel model) => AnalogClock(model)));
30+
```
31+
32+
For more information, see the code inside [lib/](lib).
33+
For a full example, see the [Analog Clock](../analog_clock) or [Digital Clock](../digital_clock) in this GitHub repo.

flutter_clock_helper/customizer.png

36.3 KB
Loading
+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
import 'model.dart';
8+
9+
/// Returns a clock [Widget] with [ClockModel].
10+
///
11+
/// Example:
12+
/// final myClockBuilder = (ClockModel model) => AnalogClock(model);
13+
///
14+
/// Contestants: Do not edit this.
15+
typedef Widget ClockBuilder(ClockModel model);
16+
17+
/// Wrapper for clock widget to allow for customizations.
18+
///
19+
/// Puts the clock in landscape orientation with an aspect ratio of 5:3.
20+
/// Provides a drawer where users can customize the data that is sent to the
21+
/// clock. To show/hide the drawer, double-tap the clock.
22+
///
23+
/// To use the [ClockCustomizer], pass your clock into it, using a ClockBuilder.
24+
///
25+
/// ```
26+
/// final myClockBuilder = (ClockModel model) => AnalogClock(model);
27+
/// return ClockCustomizer(myClockBuilder);
28+
/// ```
29+
/// Contestants: Do not edit this.
30+
class ClockCustomizer extends StatefulWidget {
31+
const ClockCustomizer(this._clock);
32+
33+
/// The clock widget with [ClockModel], to update and display.
34+
final ClockBuilder _clock;
35+
36+
@override
37+
_ClockCustomizerState createState() => _ClockCustomizerState();
38+
}
39+
40+
class _ClockCustomizerState extends State<ClockCustomizer> {
41+
final _model = ClockModel();
42+
ThemeMode _themeMode = ThemeMode.light;
43+
bool _configButtonShown = false;
44+
45+
@override
46+
void initState() {
47+
super.initState();
48+
_model.addListener(_handleModelChange);
49+
}
50+
51+
@override
52+
void dispose() {
53+
_model.removeListener(_handleModelChange);
54+
_model.dispose();
55+
super.dispose();
56+
}
57+
58+
void _handleModelChange() => setState(() {});
59+
60+
Widget _enumMenu<T>(
61+
String label, T value, List<T> items, ValueChanged<T> onChanged) {
62+
return InputDecorator(
63+
decoration: InputDecoration(
64+
labelText: label,
65+
),
66+
child: DropdownButtonHideUnderline(
67+
child: DropdownButton<T>(
68+
value: value,
69+
isDense: true,
70+
onChanged: onChanged,
71+
items: items.map((T item) {
72+
return DropdownMenuItem<T>(
73+
value: item,
74+
child: Text(enumToString(item)),
75+
);
76+
}).toList(),
77+
),
78+
),
79+
);
80+
}
81+
82+
Widget _switch(String label, bool value, ValueChanged<bool> onChanged) {
83+
return Row(
84+
children: <Widget>[
85+
Expanded(child: Text(label)),
86+
Switch(
87+
value: value,
88+
onChanged: onChanged,
89+
),
90+
],
91+
);
92+
}
93+
94+
Widget _textField(
95+
String currentValue, String label, ValueChanged<Null> onChanged) {
96+
return TextField(
97+
decoration: InputDecoration(
98+
hintText: currentValue,
99+
helperText: label,
100+
),
101+
onChanged: onChanged,
102+
);
103+
}
104+
105+
Widget _configDrawer(BuildContext context) {
106+
return SafeArea(
107+
child: Drawer(
108+
child: Padding(
109+
padding: const EdgeInsets.all(16.0),
110+
child: SingleChildScrollView(
111+
child: Column(
112+
children: <Widget>[
113+
_textField(_model.location, 'Location', (String location) {
114+
setState(() {
115+
_model.location = location;
116+
});
117+
}),
118+
_textField(_model.temperature.toString(), 'Temperature',
119+
(String temperature) {
120+
setState(() {
121+
_model.temperature = double.parse(temperature);
122+
});
123+
}),
124+
_enumMenu('Theme', _themeMode,
125+
ThemeMode.values.toList()..remove(ThemeMode.system),
126+
(ThemeMode mode) {
127+
setState(() {
128+
_themeMode = mode;
129+
});
130+
}),
131+
_switch('24-hour format', _model.is24HourFormat, (bool value) {
132+
setState(() {
133+
_model.is24HourFormat = value;
134+
});
135+
}),
136+
_enumMenu(
137+
'Weather', _model.weatherCondition, WeatherCondition.values,
138+
(WeatherCondition condition) {
139+
setState(() {
140+
_model.weatherCondition = condition;
141+
});
142+
}),
143+
_enumMenu('Units', _model.unit, TemperatureUnit.values,
144+
(TemperatureUnit unit) {
145+
setState(() {
146+
_model.unit = unit;
147+
});
148+
}),
149+
],
150+
),
151+
),
152+
),
153+
),
154+
);
155+
}
156+
157+
Widget _configButton() {
158+
return Builder(
159+
builder: (BuildContext context) {
160+
return IconButton(
161+
icon: Icon(Icons.settings),
162+
tooltip: 'Configure clock',
163+
onPressed: () {
164+
Scaffold.of(context).openEndDrawer();
165+
setState(() {
166+
_configButtonShown = false;
167+
});
168+
},
169+
);
170+
},
171+
);
172+
}
173+
174+
@override
175+
Widget build(BuildContext context) {
176+
final clock = Center(
177+
child: AspectRatio(
178+
aspectRatio: 5 / 3,
179+
child: Container(
180+
decoration: BoxDecoration(
181+
border: Border.all(
182+
width: 2,
183+
color: Theme.of(context).unselectedWidgetColor,
184+
),
185+
),
186+
child: widget._clock(_model),
187+
),
188+
),
189+
);
190+
191+
return MaterialApp(
192+
theme: ThemeData.light(),
193+
darkTheme: ThemeData.dark(),
194+
themeMode: _themeMode,
195+
debugShowCheckedModeBanner: false,
196+
home: Scaffold(
197+
resizeToAvoidBottomPadding: false,
198+
endDrawer: _configDrawer(context),
199+
body: SafeArea(
200+
child: GestureDetector(
201+
behavior: HitTestBehavior.opaque,
202+
onTap: () {
203+
setState(() {
204+
_configButtonShown = !_configButtonShown;
205+
});
206+
},
207+
child: Stack(
208+
children: [
209+
clock,
210+
if (_configButtonShown)
211+
Positioned(
212+
top: 0,
213+
right: 0,
214+
child: Opacity(
215+
opacity: 0.7,
216+
child: _configButton(),
217+
),
218+
),
219+
],
220+
),
221+
),
222+
),
223+
),
224+
);
225+
}
226+
}

0 commit comments

Comments
 (0)