-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
511 additions
and
123 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
# 第一階段-建置編譯環境&把專案編譯成Web服務 | ||
# 第一階段-建置編譯環境 | ||
FROM ubuntu:latest AS build-env | ||
|
||
# 時區 | ||
ENV TZ=Asia/Taipei | ||
RUN echo "${TZ}" > /etc/timezone | ||
RUN echo "${TZ}" > /etc/timezone | ||
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime | ||
# 1-1 安裝 flutter 相依套件 | ||
RUN apt-get update | ||
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3 sed | ||
RUN apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev | ||
RUN apt-get clean | ||
# 1-2 從源碼倉庫抓取源碼 | ||
|
||
# 安裝 Flutter 相依套件 | ||
RUN apt-get update && \ | ||
apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3 sed \ | ||
clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev && \ | ||
apt-get clean | ||
|
||
# 抓取Flutter相關函式庫 | ||
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter | ||
# 1-3 設置flutter預設路徑 | ||
|
||
# 設置 Flutter 預設路徑 | ||
ENV PATH="${PATH}:/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin" | ||
# 1-4 Run flutter doctor | ||
RUN flutter doctor -v | ||
RUN flutter channel stable | ||
RUN flutter upgrade | ||
# 1-5 復制專案到容器且開始編譯 | ||
RUN mkdir /app/ | ||
COPY . /app/ | ||
WORKDIR /app/ | ||
RUN flutter clean | ||
RUN flutter pub get | ||
|
||
# Run flutter doctor | ||
RUN flutter doctor -v \ | ||
flutter channel stable \ | ||
flutter upgrade | ||
|
||
# 建立 Web 應用程式 | ||
RUN mkdir /app | ||
COPY . /app | ||
WORKDIR /app | ||
RUN flutter clean \ | ||
flutter pub get | ||
RUN flutter build web | ||
|
||
# 第二階段-建立提供實時運作的服務 | ||
FROM nginx:alpine | ||
# 2-0 復制編譯好的檔案 | ||
FROM nginx:alpine | ||
|
||
# 復制編譯好的檔案 | ||
COPY --from=build-env /app/build/web /usr/share/nginx/html | ||
# 2-1 時區 | ||
|
||
# 時區 | ||
ENV TZ=Asia/Taipei | ||
RUN echo "${TZ}" > /etc/timezone | ||
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime | ||
# 2-2 連結埠 | ||
EXPOSE 80 | ||
RUN echo "${TZ}" > /etc/timezone | ||
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime | ||
|
||
# 連結埠 | ||
EXPOSE 80 |
This file contains 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
This file contains 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
This file contains 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
161 changes: 161 additions & 0 deletions
161
src/demo/viewapp_master/lib/pages/table/sensor01_result.dart
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, library_private_types_in_public_api, non_constant_identifier_names, prefer_interpolation_to_compose_strings, avoid_print, camel_case_types | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:viewapp_master/modules/PreferencesUtil.dart'; | ||
|
||
class Sensor01Result extends StatefulWidget { | ||
const Sensor01Result({super.key}); | ||
|
||
@override | ||
_Sensor01ResultState createState() => _Sensor01ResultState(); | ||
} | ||
|
||
class _Sensor01ResultState extends State<Sensor01Result> { | ||
late Future<Map<String, dynamic>> _dataFuture; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_dataFuture = getData(); | ||
} | ||
|
||
Future<Map<String, dynamic>> getData() async { | ||
final String? serverSource = | ||
await PreferencesUtil.getString("serverSource"); | ||
final String? username = await PreferencesUtil.getString("username"); | ||
final Uri uri = Uri.http(serverSource!, "/read/UsersComparisonResult"); | ||
final response = await http.post(uri, body: { | ||
"username": username, | ||
}, headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}); | ||
final result = response.body; | ||
final data = jsonDecode(result); | ||
print(data[0]); | ||
return Map<String, dynamic>.from(data[0]); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder<Map<String, dynamic>>( | ||
future: _dataFuture, | ||
builder: | ||
(BuildContext context, AsyncSnapshot<Map<String, dynamic>> snapshot) { | ||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
return const CircularProgressIndicator(); | ||
} else if (snapshot.hasError) { | ||
return Text('Error: ${snapshot.error}'); | ||
} else { | ||
final data = snapshot.data!; | ||
return view(data); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
Widget view(Map<String, dynamic> data) { | ||
return Column( | ||
children: <Widget>[ | ||
output(data), | ||
], | ||
); | ||
} | ||
|
||
|
||
Widget output(Map<String, dynamic> data) { | ||
return SingleChildScrollView( | ||
scrollDirection: Axis.horizontal, | ||
child: DataTable( | ||
columnSpacing: 20.0, | ||
columns: const <DataColumn>[ | ||
DataColumn( | ||
label: Text( | ||
'感測氣體', | ||
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), | ||
), | ||
), | ||
DataColumn( | ||
label: Text( | ||
'回傳值', | ||
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), | ||
), | ||
), | ||
], | ||
rows: [ | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('temp', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_temp"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('hum', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_hum"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('tvoc', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_tvoc"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('co', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_co"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('co2', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_co2"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('PM2.5', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_pm25"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
DataRow( | ||
cells: <DataCell>[ | ||
DataCell( | ||
const Text('O3', style: TextStyle(fontSize: 25)), | ||
), | ||
DataCell( | ||
Text(data["comparison_result_o3"] == 0 ? "標準" : "超標", style: TextStyle(fontSize: 25)), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.