You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/experimental/pedometer/example/lib/main.dart

209 lines
5.6 KiB

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,
),
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 {
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="https://github.com/flutter/packages/commit/3f8a5029fbb4f79f94ade1c937826b434f335469"><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="https://github.com/flutter/packages/commit/4eda7ad208d00283e1de2a65e3e803dfe9bd6d75"><code>4eda7ad</code></a> [pigeon] Fixes bug where Dart <code>FlutterApi</code>s would assert that a nullable argu...</li> <li><a href="https://github.com/flutter/packages/commit/dff39d7b48e098cff055f472d116e662b358f3c0"><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="https://github.com/flutter/packages/commit/5600590b500ea5be8fea94642439e9c3bc008767"><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="https://github.com/flutter/packages/commit/d8bf76e582c3514e7c0533de3085e70bdd847bb8"><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="https://github.com/flutter/packages/commit/bc223c127202bce429901c1070247f7bb93abe9d"><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="https://github.com/flutter/packages/commit/aff9cccafbe47913f1473e47b902585dc3079a8b"><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="https://github.com/flutter/packages/commit/84a2e796d7e5bbe8684cfaf4df0b0aeefab18042"><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="https://github.com/flutter/packages/commit/a9d6bf14ba011c8389dc2e8db713ae245a7c7293"><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="https://github.com/flutter/packages/commit/202fb329c970baf647547594cb3d18fa85fcdc68"><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>
1 year ago
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(
Bump fl_chart from 0.62.0 to 0.63.0 in /experimental/pedometer/example (#1893) Bumps [fl_chart](https://github.com/imaNNeo/fl_chart) from 0.62.0 to 0.63.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/imaNNeo/fl_chart/releases">fl_chart's releases</a>.</em></p> <blockquote> <h2>0.63.0</h2> <ul> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix PieChart crash on web-renderer html by ignoring <code>sectionsSpace</code> when <code>Path.combine()</code> does not work (it's flutter engine <a href="https://redirect.github.com/flutter/flutter/issues/44572">issue</a>), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/955">#955</a></li> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix ScatterChart long-press interaction bug (disappears when long-pressing on the chart), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/1318">#1318</a></li> <li><strong>FEATURE</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Upgrade dart version to <a href="https://dart.dev/resources/dart-3-migration">3.0</a></li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/imaNNeo/fl_chart/blob/master/CHANGELOG.md">fl_chart's changelog</a>.</em></p> <blockquote> <h2>0.63.0</h2> <ul> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix PieChart crash on web-renderer html by ignoring <code>sectionsSpace</code> when <code>Path.combine()</code> does not work (it's flutter engine <a href="https://redirect.github.com/flutter/flutter/issues/44572">issue</a>), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/955">#955</a></li> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix ScatterChart long-press interaction bug (disappears when long-pressing on the chart), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/1318">#1318</a></li> <li><strong>FEATURE</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Upgrade dart version to <a href="https://dart.dev/resources/dart-3-migration">3.0</a></li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/imaNNeo/fl_chart/commit/6c0e43f7e7409d1f65689561dcf34f88152235b8"><code>6c0e43f</code></a> Bump version to 0.63.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/81a2618d1b963b020e4c289dfd4ae754e525e04c"><code>81a2618</code></a> Update github publish action</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/3b2188d3f2aeb3aeaa0ed90ff0c7ea0d57cd4419"><code>3b2188d</code></a> Update line_chart.md</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/872878b0ce126b226507692022d0f238715408c4"><code>872878b</code></a> Fix analyze issues with Dart 3.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/2984262886f4d5cf2d73ce8d6d87425375e3593d"><code>2984262</code></a> chore: bump very_good_analysis from 4.0.0+1 to 5.0.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/ba1fa734b7dea85ac3d215032a5a90cbfaf6ad8f"><code>ba1fa73</code></a> docs wrong link fix</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/f91d4bf322ed5b2652c00972689519eb3302686f"><code>f91d4bf</code></a> Update CHANGELOG.md</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/5db8f6db61b229361e9cbdd486692b38a4d54bd5"><code>5db8f6d</code></a> Update tests to fix the CI issue</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/6db877acec6451ba46802d154f8007857311a3a5"><code>6db877a</code></a> Fix analyze issues</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/46ef2c0dc5ed3b5e2e1e90c6b75490a37a40cd94"><code>46ef2c0</code></a> Upgrade dependencies</li> <li>Additional commits viewable in <a href="https://github.com/imaNNeo/fl_chart/compare/0.62.0...0.63.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=fl_chart&package-manager=pub&previous-version=0.62.0&new-version=0.63.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 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: Hossein Yousefi <yousefi@google.com>
1 year ago
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,
Bump fl_chart from 0.62.0 to 0.63.0 in /experimental/pedometer/example (#1893) Bumps [fl_chart](https://github.com/imaNNeo/fl_chart) from 0.62.0 to 0.63.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/imaNNeo/fl_chart/releases">fl_chart's releases</a>.</em></p> <blockquote> <h2>0.63.0</h2> <ul> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix PieChart crash on web-renderer html by ignoring <code>sectionsSpace</code> when <code>Path.combine()</code> does not work (it's flutter engine <a href="https://redirect.github.com/flutter/flutter/issues/44572">issue</a>), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/955">#955</a></li> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix ScatterChart long-press interaction bug (disappears when long-pressing on the chart), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/1318">#1318</a></li> <li><strong>FEATURE</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Upgrade dart version to <a href="https://dart.dev/resources/dart-3-migration">3.0</a></li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/imaNNeo/fl_chart/blob/master/CHANGELOG.md">fl_chart's changelog</a>.</em></p> <blockquote> <h2>0.63.0</h2> <ul> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix PieChart crash on web-renderer html by ignoring <code>sectionsSpace</code> when <code>Path.combine()</code> does not work (it's flutter engine <a href="https://redirect.github.com/flutter/flutter/issues/44572">issue</a>), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/955">#955</a></li> <li><strong>BUGFIX</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Fix ScatterChart long-press interaction bug (disappears when long-pressing on the chart), <a href="https://redirect.github.com/imaNNeo/fl_chart/issues/1318">#1318</a></li> <li><strong>FEATURE</strong> (by <a href="https://github.com/imaNNeo"><code>@​imaNNeo</code></a>) Upgrade dart version to <a href="https://dart.dev/resources/dart-3-migration">3.0</a></li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/imaNNeo/fl_chart/commit/6c0e43f7e7409d1f65689561dcf34f88152235b8"><code>6c0e43f</code></a> Bump version to 0.63.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/81a2618d1b963b020e4c289dfd4ae754e525e04c"><code>81a2618</code></a> Update github publish action</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/3b2188d3f2aeb3aeaa0ed90ff0c7ea0d57cd4419"><code>3b2188d</code></a> Update line_chart.md</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/872878b0ce126b226507692022d0f238715408c4"><code>872878b</code></a> Fix analyze issues with Dart 3.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/2984262886f4d5cf2d73ce8d6d87425375e3593d"><code>2984262</code></a> chore: bump very_good_analysis from 4.0.0+1 to 5.0.0</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/ba1fa734b7dea85ac3d215032a5a90cbfaf6ad8f"><code>ba1fa73</code></a> docs wrong link fix</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/f91d4bf322ed5b2652c00972689519eb3302686f"><code>f91d4bf</code></a> Update CHANGELOG.md</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/5db8f6db61b229361e9cbdd486692b38a4d54bd5"><code>5db8f6d</code></a> Update tests to fix the CI issue</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/6db877acec6451ba46802d154f8007857311a3a5"><code>6db877a</code></a> Fix analyze issues</li> <li><a href="https://github.com/imaNNeo/fl_chart/commit/46ef2c0dc5ed3b5e2e1e90c6b75490a37a40cd94"><code>46ef2c0</code></a> Upgrade dependencies</li> <li>Additional commits viewable in <a href="https://github.com/imaNNeo/fl_chart/compare/0.62.0...0.63.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=fl_chart&package-manager=pub&previous-version=0.62.0&new-version=0.63.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 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: Hossein Yousefi <yousefi@google.com>
1 year ago
gridData: const FlGridData(show: false),
alignment: BarChartAlignment.spaceAround,
),
),
),
),
),
],
));
}
}
// Axis labels for bottom of chart.
Widget getBottomTitles(double value, TitleMeta meta) {
final timeText = switch (value.toInt()) {
0 => '12AM',
6 => '6AM',
12 => '12PM',
18 => '6PM',
_ => ''
};
return SideTitleWidget(
axisSide: meta.axisSide,
space: 4,
child: Text(
timeText,
style: TextStyle(fontSize: 14, color: Colors.blue[900]),
),
);
}