1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +00:00
Files
samples/experimental/pedometer/example/lib/main.dart
dependabot[bot] 8e14f553ce Bump flutter_lints from 2.0.3 to 3.0.0 in /experimental/pedometer/example (#2047)
Bumps
[flutter_lints](https://github.com/flutter/packages/tree/main/packages)
from 2.0.3 to 3.0.0.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="3f8a5029fb"><code>3f8a502</code></a>
[pigeon] Remove support for non-NNBD (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1524">#1524</a>)</li>
<li><a
href="4eda7ad208"><code>4eda7ad</code></a>
[pigeon] Fixes bug where Dart <code>FlutterApi</code>s would assert that
a nullable argu...</li>
<li><a
href="dff39d7b48"><code>dff39d7</code></a>
[go_router]refactor runtime check to assert (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1362">#1362</a>)</li>
<li><a
href="5600590b50"><code>5600590</code></a>
[go_router] Export inherited_go_router.dart file (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1145">#1145</a>)</li>
<li><a
href="d8bf76e582"><code>d8bf76e</code></a>
[flutter_markdown] Remove build status from <code>README.md</code> (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1326">#1326</a>)</li>
<li><a
href="bc223c1272"><code>bc223c1</code></a>
Remove checked in binaries from flutter/packages. (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1338">#1338</a>)</li>
<li><a
href="aff9cccafb"><code>aff9ccc</code></a>
[rfw] Run tests for package:rfw on stable as well. (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/888">#888</a>)</li>
<li><a
href="84a2e796d7"><code>84a2e79</code></a>
[Pigeon] Make the generated Java Builder class final (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1247">#1247</a>)</li>
<li><a
href="a9d6bf14ba"><code>a9d6bf1</code></a>
[go_router] improve coverage (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/977">#977</a>)</li>
<li><a
href="202fb329c9"><code>202fb32</code></a>
[flutter_lints] version 2.0 (<a
href="https://github.com/flutter/packages/tree/main/packages/issues/1165">#1165</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/flutter/packages/commits/pigeon-v3.0.0/packages">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=flutter_lints&package-manager=pub&previous-version=2.0.3&new-version=3.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brett Morgan <brettmorgan@google.com>
2023-10-20 09:53:36 +10:00

217 lines
5.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:fl_chart/fl_chart.dart';
import 'steps_repo.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const Home(),
);
}
}
class RoundClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final diameter = size.shortestSide * 1.5;
final x = -(diameter - size.width) / 2;
final y = size.height - diameter;
final rect = Offset(x, y) & Size(diameter, diameter);
return Path()..addOval(rect);
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
var hourlySteps = <Steps>[];
DateTime? lastUpdated;
@override
void initState() {
runPedometer();
super.initState();
}
void runPedometer() async {
final now = DateTime.now();
hourlySteps = await StepsRepo.instance.getSteps();
lastUpdated = now;
setState(() {});
}
@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
final barGroups = hourlySteps
.map(
(e) => BarChartGroupData(
x: int.parse(e.startHour),
barRods: [
BarChartRodData(
color: Colors.blue[900],
toY: e.steps.toDouble() / 100,
)
],
),
)
.toList();
return Scaffold(
body: Stack(
children: [
ClipPath(
clipper: RoundClipper(),
child: FractionallySizedBox(
heightFactor: 0.55,
widthFactor: 1,
child: Container(color: Colors.blue[300]),
),
),
Align(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.all(80.0),
child: Column(
children: [
lastUpdated != null
? Padding(
padding: const EdgeInsets.symmetric(vertical: 50.0),
child: Text(
DateFormat.yMMMMd('en_US').format(lastUpdated!),
style: textTheme.titleLarge!
.copyWith(color: Colors.blue[900]),
),
)
: const SizedBox(height: 0),
Text(
hourlySteps.fold(0, (t, e) => t + e.steps).toString(),
style: textTheme.displayMedium!.copyWith(color: Colors.white),
),
Text(
'steps',
style: textTheme.titleLarge!.copyWith(color: Colors.white),
)
],
),
),
),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: runPedometer,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
decoration: BoxDecoration(
color: Colors.blue[900],
shape: BoxShape.circle,
),
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.refresh,
color: Colors.white,
size: 50,
),
),
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 30.0, vertical: 50.0),
child: AspectRatio(
aspectRatio: 1.2,
child: BarChart(
BarChartData(
titlesData: const FlTitlesData(
show: true,
// Top titles are null
topTitles:
AxisTitles(sideTitles: SideTitles(showTitles: false)),
rightTitles:
AxisTitles(sideTitles: SideTitles(showTitles: false)),
leftTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: false,
),
),
bottomTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
reservedSize: 30,
getTitlesWidget: getBottomTitles,
),
),
),
borderData: FlBorderData(
show: false,
),
barGroups: barGroups,
gridData: const FlGridData(show: false),
alignment: BarChartAlignment.spaceAround,
),
),
),
),
),
],
));
}
}
// Axis labels for bottom of chart
Widget getBottomTitles(double value, TitleMeta meta) {
String text;
switch (value.toInt()) {
case 0:
text = '12AM';
break;
case 6:
text = '6AM';
break;
case 12:
text = '12PM';
break;
case 18:
text = '6PM';
break;
default:
text = '';
}
return SideTitleWidget(
axisSide: meta.axisSide,
space: 4,
child: Text(text, style: TextStyle(fontSize: 14, color: Colors.blue[900])),
);
}