Last active
April 24, 2024 14:39
-
-
Save JohanScheepers/5554a93936fdc4797aa5f3fd2198b01b to your computer and use it in GitHub Desktop.
Gauges and Charts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| title: 'Gauges and Charts', | |
| theme: ThemeData( | |
| colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | |
| useMaterial3: true, | |
| ), | |
| home: const GaugesAndCharts(title: 'Gauges and Charts'), | |
| ); | |
| } | |
| } | |
| class GaugesAndCharts extends StatefulWidget { | |
| const GaugesAndCharts({super.key, required this.title}); | |
| final String title; | |
| @override | |
| State<GaugesAndCharts> createState() => _GaugesAndChartsState(); | |
| } | |
| class _GaugesAndChartsState extends State<GaugesAndCharts> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
| title: Text(widget.title), | |
| ), | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| ElevatedButton( | |
| onPressed: () { | |
| Navigator.push( | |
| context, | |
| MaterialPageRoute( | |
| builder: (context) => const Gauge(), | |
| ), | |
| ); | |
| }, | |
| child: const Text("Gauge"), | |
| ), | |
| const SizedBox( | |
| height: 10, | |
| ), | |
| ElevatedButton( | |
| onPressed: () { | |
| Navigator.push(context, | |
| MaterialPageRoute(builder: (context) => const Chart())); | |
| }, | |
| child: const Text("Chart"), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class Gauge extends StatefulWidget { | |
| const Gauge({super.key}); | |
| @override | |
| State<Gauge> createState() => _GaugeState(); | |
| } | |
| class _GaugeState extends State<Gauge> { | |
| List<RoomData> chartData = <RoomData>[ | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 00, 07, 03), | |
| temprature: 19.0, | |
| humidity: 82.0), | |
| ]; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
| title: const Text("Gauge"), | |
| ), | |
| body: const Placeholder()); | |
| } | |
| } | |
| class Chart extends StatefulWidget { | |
| const Chart({super.key}); | |
| @override | |
| State<Chart> createState() => _ChartState(); | |
| } | |
| class _ChartState extends State<Chart> { | |
| List<RoomData> chartData = <RoomData>[ | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 00, 07, 03), | |
| temprature: 19.0, | |
| humidity: 82.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 01, 08, 03), | |
| temprature: 17.3, | |
| humidity: 81.5), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 02, 05, 03), | |
| temprature: 15.0, | |
| humidity: 83.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 03, 06, 03), | |
| temprature: 18.2, | |
| humidity: 82.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 04, 07, 03), | |
| temprature: 19.0, | |
| humidity: 84.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 05, 08, 03), | |
| temprature: 17.3, | |
| humidity: 95.3), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 06, 05, 03), | |
| temprature: 15.0, | |
| humidity: 94.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 07, 06, 03), | |
| temprature: 18.2, | |
| humidity: 89.8), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 08, 07, 03), | |
| temprature: 19.0, | |
| humidity: 88.6), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 09, 08, 03), | |
| temprature: 17.3, | |
| humidity: 87.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 10, 09, 03), | |
| temprature: 18.1, | |
| humidity: 85.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 11, 10, 03), | |
| temprature: 11.0, | |
| humidity: 84.3), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 12, 11, 03), | |
| temprature: 14.0, | |
| humidity: 84.7), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 13, 05, 03), | |
| temprature: 15.0, | |
| humidity: 82.3), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 14, 06, 03), | |
| temprature: 18.2, | |
| humidity: 81.9), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 15, 07, 03), | |
| temprature: 19.0, | |
| humidity: 79.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 16, 08, 03), | |
| temprature: 17.3, | |
| humidity: 75.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 17, 09, 03), | |
| temprature: 18.1, | |
| humidity: 76.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 18, 10, 03), | |
| temprature: 11.0, | |
| humidity: 77.5), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 19, 11, 03), | |
| temprature: 14.0, | |
| humidity: 78.3), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 20, 07, 03), | |
| temprature: 19.0, | |
| humidity: 81.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 21, 08, 03), | |
| temprature: 17.3, | |
| humidity: 85.0), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 22, 09, 03), | |
| temprature: 18.1, | |
| humidity: 86.2), | |
| RoomData( | |
| timestamp: DateTime(2024, 03, 22, 23, 10, 03), | |
| temprature: 11.0, | |
| humidity: 85.0), | |
| ]; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| backgroundColor: Theme.of(context).colorScheme.inversePrimary, | |
| title: const Text("Chart"), | |
| ), | |
| body: const Placeholder()); | |
| } | |
| } | |
| class RoomData { | |
| RoomData({this.timestamp, this.temprature, this.humidity}); | |
| final DateTime? timestamp; | |
| final double? temprature; | |
| final double? humidity; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment