Skip to content

Commit

Permalink
20240322 update2
Browse files Browse the repository at this point in the history
  • Loading branch information
neko0xff committed Mar 22, 2024
1 parent 6b5233a commit 27dbc44
Show file tree
Hide file tree
Showing 15 changed files with 511 additions and 123 deletions.
61 changes: 35 additions & 26 deletions src/demo/viewapp_master/Dockerfile.env
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
2 changes: 1 addition & 1 deletion src/demo/viewapp_master/lib/pages/btn/view/Cfoot_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DataAQI extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("碳排放",
Text("碳排放計算",
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
SizedBox(width: 10),
]),
Expand Down
24 changes: 23 additions & 1 deletion src/demo/viewapp_master/lib/pages/out/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'package:flutter/material.dart';
import 'package:viewapp_master/modules/PreferencesUtil.dart';
import 'package:viewapp_master/pages/table/switch01.dart';
import 'package:viewapp_master/pages/table/sensor01_result.dart';
import 'package:viewapp_master/pages/widget/wallpaper.dart';

class Main extends StatelessWidget {
Expand All @@ -15,7 +16,7 @@ class Main extends StatelessWidget {
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.blue, backgroundColor: Colors.white),
primarySwatch: Colors.yellow, backgroundColor: Colors.white),
),
home: const Scaffold(
body: MainPage(),
Expand Down Expand Up @@ -50,6 +51,13 @@ class MainPage extends StatelessWidget {
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const Data3(),
const SizedBox(height: 10.0),
const Text('感測器狀態',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 10.0),
const Text('Sensor01',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const Data4(),
const SizedBox(height: 10.0),
wallpaperLogin(),
],
));
Expand Down Expand Up @@ -135,3 +143,17 @@ class Data3 extends StatelessWidget {
);
}
}

class Data4 extends StatelessWidget {
const Data4({super.key});

@override
Widget build(BuildContext context) {
return const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [Sensor01Result()]),
);
}
}
2 changes: 1 addition & 1 deletion src/demo/viewapp_master/lib/pages/out/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class btn3 extends StatelessWidget {
Navigator.push(
context, MaterialPageRoute(builder: (context) => CfootPage_api()));
},
child: Text('碳排放', textAlign: TextAlign.center));
child: Text('碳排放計算', textAlign: TextAlign.center));
}
}

Expand Down
161 changes: 161 additions & 0 deletions src/demo/viewapp_master/lib/pages/table/sensor01_result.dart
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)),
),
],
),
],
),
);
}
}
2 changes: 1 addition & 1 deletion src/demo/viewapp_master/lib/pages/table/switch01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _SwitchTable1State extends State<SwitchTable1> {
style: const TextStyle(fontSize: 25)),
),
DataCell(
Text('${data[index]["status"]}',
Text(data[index]["status"] == 0 ? "關" : "開",
style: const TextStyle(fontSize: 25)),
),
],
Expand Down
34 changes: 19 additions & 15 deletions src/demo/viewapp_master/lib/pages/widget/CBAM/CC_simple_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ class _InputGetState extends State<InputGet> {
PostStr(),
SizedBox(height: 10.0),
Text("公式: 產品碳含量= 排放量/產品活動數據(生產量)"),
Text("備註: 簡單和中間產品的運算公式相同"),
SizedBox(height: 10.0),
BtnView(),
SizedBox(height: 10.0),

],
),
);
Expand All @@ -88,12 +90,15 @@ class PostStr extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("排放來源",style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
Text("特定產品排放量",style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Text("指定生產的產品",style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold)),
DbCPL(),
Tbuse(),
Text("排放來源",style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
Tbproduction()
SizedBox(height: 10),
Text("產品活動數據",style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Tbproduction(),
],
);
}
Expand Down Expand Up @@ -228,10 +233,10 @@ class BtnClear extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 100.0,
width: 140.0,
height: 50.0,
child: ElevatedButton(
child: const Text("Clear"),
child: const Text("清除填入內容"),
onPressed: () {
clearInput();
},
Expand Down Expand Up @@ -259,15 +264,14 @@ class BtnView extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
BtnStrSend(),
],
),
SizedBox(height: 10.0),
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
BtnClear(),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
BtnStrSend(),
SizedBox(width: 10.0,height: 10.0),
BtnClear(),
])
],
),
SizedBox(height: 10.0),
Expand Down Expand Up @@ -392,7 +396,7 @@ class BtnGoBack extends StatelessWidget {
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(minimumSize: const Size(100, 50)),
child: const Text('Go Back'),
child: const Text('回上頁'),
),
);
}
Expand Down
Loading

0 comments on commit 27dbc44

Please sign in to comment.