master
EduCoderStudent0014 1 year ago
parent 0e219b5ffc
commit 9c4c8c7acb

321
.gitignore vendored

@ -0,0 +1,321 @@
# Created by .ignore support plugin (hsz.mobi)
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
medicine-server/src/main/resources/application.yml
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### C++ template
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### C template
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
**/.gradle
**/node_modules
medicine-server/src/main/java/cn/xiaohaoo/admin/service/MedicinePredictionService.java
medicine-server/src/main/resources/onnx/medicine_model.onnx

@ -0,0 +1,121 @@
木兰宽松许可证, 第1版
木兰宽松许可证, 第1版
2019年8月 http://license.coscl.org.cn/MulanPSL
您对“软件”的复制、使用、修改及分发受木兰宽松许可证第1版“本许可证”的如下条款的约束
0. 定义
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
“法人实体”是指提交贡献的机构及其“关联实体”。
“关联实体”是指对“本许可证”下的一方而言控制、受控制或与其共同受控制的机构此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
1. 授予版权许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
2. 授予专利许可
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括仅因您或他人修改“贡献”或其他结合而将必然会侵犯到的专利权利要求。如您或您的“关联实体”直接或间接地(包括通过代理、专利被许可人或受让人),就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
3. 无商标许可
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可但您为满足第4条规定的声明义务而必须使用除外。
4. 分发限制
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
5. 免责声明与责任限制
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
条款结束。
如何将木兰宽松许可证第1版应用到您的软件
如果您希望将木兰宽松许可证第1版应用到您的新软件为了方便接收者查阅建议您完成如下三步
1 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
2 请您在软件包的一级目录下创建以“LICENSE”为名的文件将整个许可证文本放入该文件中
3 请将如下声明文本放入每个源文件的头部注释中。
Copyright (c) 2019-2020 李文浩
Chinese Medicine Identification is licensed under the Mulan PSL v1.
You can use this software according to the terms and conditions of the Mulan PSL v1.
You may obtain a copy of Mulan PSL v1 at:
http://license.coscl.org.cn/MulanPSL
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
PURPOSE.
See the Mulan PSL v1 for more details.
Mulan Permissive Software LicenseVersion 1
Mulan Permissive Software LicenseVersion 1 (Mulan PSL v1)
August 2019 http://license.coscl.org.cn/MulanPSL
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v1 (this License) with following terms and conditions:
0. Definition
Software means the program and related documents which are comprised of those Contribution and licensed under this License.
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
Legal Entity means the entity making a Contribution and all its Affiliates.
Affiliates means entities that control, or are controlled by, or are under common control with a party to this License, control means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
Contribution means the copyrightable work licensed by a particular Contributor under this License.
1. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
2. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed, excluding of any patent claims solely be infringed by your or others modification or other combinations. If you or your Affiliates directly or indirectly (including through an agent, patent licensee or assignee, institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
3. No Trademark License
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
4. Distribution Restriction
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
5. Disclaimer of Warranty and Limitation of Liability
The Software and Contribution in it are provided without warranties of any kind, either express or implied. In no event shall any Contributor or copyright holder be liable to you for any damages, including, but not limited to any direct, or indirect, special or consequential damages arising from your use or inability to use the Software or the Contribution in it, no matter how its caused or based on which legal theory, even if advised of the possibility of such damages.
End of the Terms and Conditions
How to apply the Mulan Permissive Software LicenseVersion 1 (Mulan PSL v1) to your software
To apply the Mulan PSL v1 to your work, for easy identification by recipients, you are suggested to complete following three steps:
i. Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
ii. Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
iii. Attach the statement to the appropriate annotated syntax at the beginning of each source file.
Copyright (c) 2019-2020 李文浩
Chinese Medicine Identification is licensed under the Mulan PSL v1.
You can use this software according to the terms and conditions of the Mulan PSL v1.
You may obtain a copy of Mulan PSL v1 at:
http://license.coscl.org.cn/MulanPSL
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
PURPOSE.
See the Mulan PSL v1 for more details.

@ -1,2 +1,311 @@
# TraditionalChineseMedicineRecognition <h1 align="center">
<strong>中药图片拍照识别系统-移动端+后端</strong>
</h1>
<p align="center">
<img src="https://img.shields.io/badge/release-v3.1-green.svg"/>
<img src="https://img.shields.io/badge/language-Java 11-green.svg" />
<img src="https://img.shields.io/badge/language-Python 3-green.svg" />
<img src="https://img.shields.io/badge/dependency-SpringBoot-green.svg" />
<img src="https://img.shields.io/badge/dependency-TensorFlow-green.svg" />
<img src="https://img.shields.io/badge/license-MulanPSL-green.svg" />
</p>
## 项目说明
中药识别系统主要采用APP端拍照上传的方式构建卷积神经网络CNN对图像进行识别具有识别效率高准确度高的特点。APP端的功能包括但不限于拍照识别、中药问答付费咨询、检索查询、中药性状以及功效查看、方剂智能推荐【开发中】等本系统包含APP端以及服务器端。
## 版本说明 3.x
1. APP端使用**Flutter**重写界面,使用体验得到提升。
2. 深度学习运行时框架采用**ONNX Runtime**。**计算速度**得到明显加快,同时深度学习框架依赖部署文件减小到**40M**。
## 项目介绍
**本项目包含六个模块:**
- **medicine-app**[APP端](medicine-app)
- **medicine-server**[服务器端](medicine-server)
- **medicine-crawler**[爬虫工程](medicine-crawler)
- **medicine-model**[卷积神经网络](medicine-model)
- **medicine-util**[公用工具类](medicine-util)
- **medicine-dataset**[数据集](medicine-dataset)
## 项目预览
- **项目运行展示**
<table>
<tr>
<td>
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/启动屏.png" width="191px" height="338px" alt="">
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/首页.png" width="191px" height="338px" alt="">
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/筛选.png" width="191px" height="338px" alt="">
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/中药详细信息.png" width="191px" height="338px" alt="">
</td>
</tr>
<tr>
<td>
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/拍照识别.png" width="191px" height="338px" alt="">
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/预测结果.png" width="191px" height="338px" alt="">
<img src="https://gitee.com/xiaohaoo/chinese-medicine-identification/raw/master/assets/搜索结果.png" width="191px" height="338px" alt="">
</td>
</tr>
</table>
- [**视频演示**](https://www.bilibili.com/video/BV14T4y157rM)
- [**APP下载地址**](https://gitee.com/xiaohaoo/chinese-medicine-identification/releases)
## 开发文档
[阅读文档](http://xiaohaoo.gitee.io/chinese-medicine-identification-admin/)
## 技术简介
1. **medicine-app APP端**
- Flutter开发
2. **medicine-server服务器端工程**
Gradle构建
SpringBoot框架,一键启动与部署
文档数据库MongoDB
全文检索Elasticsearch + IK分词器
数据库MySQL
深度学习运行时架构ONNX RuntimeONNX Runtime is a cross-platform inference and training machine-learning accelerator
3. **medicine-crawler爬虫工程**
爬虫主要用来爬取**训练集**以及**中药的详细信息**,包含但不限于:中药名称、中药形态、图片、
别名、英文名、配伍药方、功效与作用、临床应用、产地分布、药用部位、
性味归经、药理研究、主要成分、使用禁忌、采收加工、药材性状等信息。
爬虫框架WebMagic[参考代码](./medicine-crawler/src/main/java/cn/xiaohaoo/datacollection/MedicineCountPageProcessor.java)
数据持久化MongoDB
数据结构(简略展示)
- 中药一级分类信息
![](./medicine-doc/assets/images/中药分类信息.jpg)
- 中药详细信息
![](./medicine-doc/assets/images/中药详细信息.jpg)
4. **medicine-model卷积神经网络工程**
- Language: Python
- 使用TensorFlow 深度学习框架使用Keras会大幅缩减代码量
- [数据集](medicine-dataset)
- 常用的**卷积网络模型**及在ImageNet上的准确率
|模型|大小|Top-1准确率|Top-5准确率|参数数量|深度|
|:---:|:---:|:---:|:---:|:---:|:---:|
|**Xception**|**88 MB**|**0.790**|**0.945**|**22,910,480**|**126**|
|VGG16|528 MB|0.713|0.901|138,357,544|23|
|VGG19|549 MB|0.713|0.900|143,667,240|26|
|ResNet50|98 MB|0.749|0.921|25,636,712|168|
|ResNet101|171 MB|0.764|0.928|44,707,176|-|
|ResNet152|232 MB|0.766|0.931|60,419,944|-|
|ResNet50V2|98 MB|0.760|0.930|25,613,800|-|
|ResNet101V2|171 MB|0.772|0.938|44,675,560|-|
|ResNet152V2|232 MB|0.780|0.942|60,380,648|-|
|ResNeXt50|96 MB|0.777|0.938|25,097,128|-|
|ResNeXt101|170 MB|0.787|0.943|44,315,560|-|
|InceptionV3|92 MB|0.779|0.937|23,851,784|159|
|InceptionResNetV2|215 MB|0.803|0.953|55,873,736|572|
|MobileNet|16 MB|0.704|0.895|4,253,864|88|
|MobileNetV2|14 MB|0.713|0.901|3,538,984|88|
|DenseNet121|33 MB| 0.750|0.923|8,062,504|121|
|DenseNet169|57 MB| 0.762|0.932|14,307,880|169|
|DenseNet201|80 MB|0.773|0.936|20,242,984|201|
|NASNetMobile|23 MB|0.744|0.919|5,326,716|-|
|NASNetLarge|343 MB|0.825|0.960|88,949,818|-|
由于硬件条件限制,综合考虑模型的准确率、大小以及复杂度等因素,采用了**Xception模型**该模型是134层包含激活层批标准化层等拓扑深度的卷积网络模型。
- **Xception函数定义**
```python
def Xception(include_top=True,
weights='imagenet',
input_tensor=None,
input_shape=None,
pooling=None,
classes=1000,
**kwargs)
# 参数
# include_top是否保留顶层的全连接网络
# weightsNone代表随机初始化即不加载预训练权重。'imagenet代表加载预训练权重
# input_tensor可填入Keras tensor作为模型的图像输入tensor
# input_shape可选仅当include_top=False有效应为长为3的tuple指明输入图片的shape图片的宽高必须大于71如(150,150,3)
# pooling当include_top=False时该参数指定了池化方式。None代表不池化最后一个卷积层的输出为4D张量。avg代表全局平均池化max代表全局最大值池化。
# classes可选图片分类的类别数仅当include_top=True并且不加载预训练权重时可用
```
- **构建代码**
[基于Xception的模型微调,详细请参考代码](medicine-model/src)
1. 设置Xception参数
迁移学习参数权重加载xception_weights
```python
# 设置输入图像的宽高以及通道数
img_size = (299, 299, 3)
base_model = keras.applications.xception.Xception(include_top=False,
weights='..\\resources\\keras-model\\xception_weights_tf_dim_ordering_tf_kernels_notop.h5',
input_shape=img_size,
pooling='avg')
# 全连接层使用softmax激活函数计算概率值分类大小是628
model = keras.layers.Dense(628, activation='softmax', name='predictions')(base_model.output)
model = keras.Model(base_model.input, model)
# 锁定卷积层
for layer in base_model.layers:
layer.trainable = False
```
2. 全连接层训练(v1.0)
```python
from base_model import model
# 设置训练集图片大小以及目录参数
img_size = (299, 299)
dataset_dir = '..\\dataset\\dataset'
img_save_to_dir = 'resources\\image-traing\\'
log_dir = 'resources\\train-log'
model_dir = 'resources\\keras-model\\'
# 使用数据增强
train_datagen = keras.preprocessing.image.ImageDataGenerator(
rescale=1. / 255,
shear_range=0.2,
width_shift_range=0.4,
height_shift_range=0.4,
rotation_range=90,
zoom_range=0.7,
horizontal_flip=True,
vertical_flip=True,
preprocessing_function=keras.applications.xception.preprocess_input)
test_datagen = keras.preprocessing.image.ImageDataGenerator(
preprocessing_function=keras.applications.xception.preprocess_input)
train_generator = train_datagen.flow_from_directory(
dataset_dir,
save_to_dir=img_save_to_dir,
target_size=img_size,
class_mode='categorical')
validation_generator = test_datagen.flow_from_directory(
dataset_dir,
save_to_dir=img_save_to_dir,
target_size=img_size,
class_mode='categorical')
# 早停法以及动态学习率设置
early_stop = EarlyStopping(monitor='val_loss', patience=13)
reduce_lr = ReduceLROnPlateau(monitor='val_loss', patience=7, mode='auto', factor=0.2)
tensorboard = keras.callbacks.tensorboard_v2.TensorBoard(log_dir=log_dir)
for layer in model.layers:
layer.trainable = False
# 模型编译
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
history = model.fit_generator(train_generator,
steps_per_epoch=train_generator.samples // train_generator.batch_size,
epochs=100,
validation_data=validation_generator,
validation_steps=validation_generator.samples // validation_generator.batch_size,
callbacks=[early_stop, reduce_lr, tensorboard])
# 模型导出
model.save(model_dir + 'chinese_medicine_model_v1.0.h5')
```
3. 对于顶部的6层卷积层我们使用数据集对权重参数进行微调
```python
# 加载模型
model=keras.models.load_model('resources\\keras-model\\chinese_medicine_model_v2.0.h5')
for layer in model.layers:
layer.trainable = False
for layer in model.layers[126:132]:
layer.trainable = True
history = model.fit_generator(train_generator,
steps_per_epoch=train_generator.samples // train_generator.batch_size,
epochs=100,
validation_data=validation_generator,
validation_steps=validation_generator.samples // validation_generator.batch_size,
callbacks=[early_stop, reduce_lr, tensorboard])
model.save(model_dir + 'chinese_medicine_model_v2.0.h5')
```
4. 服务器端使用ONNX Runtime调用训练好的模型
- **模型概览**
[模型详细结构](medicine-doc/assets/images/model.png)
- **训练过程正确率以及损失函数可视化展示**
![正确率](medicine-doc/assets/images/正确率.png)
![损失函数](medicine-doc/assets/images/损失函数.png)
5. **medicine-dataset数据集**
- [数据集:](medicine-dataset/dataset2)像素299*299
- [中药名字编码表](medicine-doc/assets/medicine_label.txt)
6. **medicine-util公用工具类**
- 关于[MongoDbUtil](medicine-util/src/main/java/cn/xiaohaoo/medicine/util/mongo/)说明
## 依赖环境说明
|依赖|版本|
|:---:|:---:|
|JDK|11+|
|Python|3.6|
|Gradle|6.5|
|TensorFlow|2.0|
|MongoDB|4.2.2|
|MySQL|8.0+|
|Spring Boot|2.2.2|
|Elasticsearch|7.4.2|
|IK分词器|7.4.2|
|ONNX Runtime|1.8.1|
## 开源软件使用须知
- **允许用于个人学习;**
- **开源版不适合商用;**
- **禁止将本项目的代码和资源进行任何形式的出售,产生的一切任何后果责任由侵权者自负;**
- **[LICENSE](LICENSE)**
## 交流、反馈与参与贡献
- 如需关注项目最新动态请Watch、Star项目同时也是对项目最好的支持
- 欢迎参与技术讨论、二次开发等咨询、问题和建议!
- QQ993021993
- 微信:
![WECHAT](medicine-doc/assets/WECHAT.png)
#### 开源不易感谢各位朋友的star ^_^

@ -0,0 +1,46 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
# Web related
lib/generated_plugin_registrant.dart
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

@ -0,0 +1,3 @@
# 中药识别APP端
使用Flutter开发

@ -0,0 +1,11 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties

@ -0,0 +1,59 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId 'cn.xiaohao.medicine'
minSdkVersion 19
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xiaohao.flutter_demo01">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

@ -0,0 +1,44 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xiaohao.flutter_demo01">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="中药识别"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>

@ -0,0 +1,6 @@
package com.xiaohao.flutter_demo01
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?><!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
<item
android:layout_height="200dp">
<bitmap
android:layout_height="wrap_content"
android:height="200dp"
android:src="@drawable/launcher" />
</item>
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?><!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<item
android:layout_height="500dp">
<bitmap
android:src="@drawable/launcher" />
</item>
</layer-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com.xiaohao.flutter_demo01">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

@ -0,0 +1,29 @@
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}

@ -0,0 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

@ -0,0 +1,11 @@
include ':app'
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

@ -0,0 +1,199 @@
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:medicine_app/request_util.dart';
import 'package:medicine_app/search_page.dart';
import 'package:medicine_app/slide_page_route.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'medicine_detail_page.dart';
class HomePage extends StatefulWidget {
HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).accentColor,
elevation: 2,
shadowColor: Theme.of(context).shadowColor,
toolbarHeight: 50,
title: TextButton(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.search_sharp,
size: 17,
),
Text('搜索')
],
),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all(Colors.grey.shade500),
shadowColor: MaterialStateProperty.all(Colors.transparent),
overlayColor: MaterialStateProperty.all(Colors.transparent),
minimumSize: MaterialStateProperty.all(Size.fromHeight(32)),
backgroundColor: MaterialStateProperty.all(Colors.white24.withOpacity(0.80)),
textStyle: MaterialStateProperty.all(TextStyle(fontSize: 13, letterSpacing: 2)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)),
),
),
onPressed: () => Navigator.of(context).push(SlidePageRoute(builder: SearchMedicinePage())),
),
),
body: FutureBuilder(future: Future.sync(() {
return Request.getDio().get('/medicine/outlines');
}), builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
Map data = json.decode(snapshot.data.toString());
final List<dynamic> medicineList = data['data'];
return ListView.builder(
cacheExtent: 10,
padding: EdgeInsets.only(bottom: 30),
itemCount: medicineList.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index < medicineList.length) {
final Map medicine = medicineList[index];
final List<dynamic> medicineDetails = medicine['details'];
return Card(
color: Colors.grey[10],
shadowColor: Colors.grey[50],
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
borderOnForeground: false,
margin: EdgeInsets.symmetric(vertical: 5, horizontal: 5),
//
child: Container(
margin: EdgeInsets.symmetric(vertical: 5, horizontal: 5),
height: 250,
child: Column(
children: [
Expanded(
flex: 1,
child: ListTile(
title: Text(
"${medicine['name']}",
style: TextStyle(fontWeight: FontWeight.bold),
)),
),
Expanded(
flex: 3,
child: Builder(builder: (context) {
final int pageCount = (medicineDetails.length / 6).ceil();
final int maxPageCount = medicineDetails.length;
final controller = PageController();
return Padding(
padding: EdgeInsets.only(bottom: 3),
child: Stack(
alignment: Alignment.bottomCenter,
children: [
SmoothPageIndicator(
controller: controller, // PageController
count: pageCount,
effect: WormEffect(dotWidth: 7, dotHeight: 7)),
PageView(
children: List.generate(pageCount, (index) {
return GridView.count(
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: 3,
mainAxisSpacing: 20,
crossAxisSpacing: 35,
padding: EdgeInsets.symmetric(
horizontal: 30,
),
children: medicineDetails
.sublist(index * 6, min((index + 1) * 6, maxPageCount))
.map((e) {
return GestureDetector(
onTap: () {
Navigator.of(context).push(SlidePageRoute(
builder: MedicineDetailPage(name: "${e['text']}"),
));
},
child: Column(
children: [
Expanded(
flex: 2,
child: null != e['icon']
? CircleAvatar(
backgroundColor:
Theme.of(context).secondaryHeaderColor,
backgroundImage: Image.network(
e['icon'],
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
} else {
return Icon(Icons.downloading_outlined);
}
},
).image,
radius: 50,
)
: CircleAvatar(
backgroundColor:
Theme.of(context).secondaryHeaderColor,
)),
Expanded(
flex: 1,
child: Text(
'${e['text']}',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w400,
color: Colors.black.withAlpha(170)),
),
)
],
),
);
}).toList());
}).toList(),
controller: controller,
)
],
),
);
}))
],
),
),
);
} else {
return Container(
alignment: Alignment.center,
child: Text(
'- 没有更多了 -',
style: TextStyle(color: Colors.grey),
),
);
}
});
} else {
return Center(
child: SpinKitFadingCircle(
color: Theme.of(context).primaryColor,
size: 32,
));
}
}),
);
}
}

@ -0,0 +1,173 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:medicine_app/mine_page.dart';
import 'package:medicine_app/prediction_list_page.dart';
import 'package:medicine_app/request_util.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:medicine_app/slide_page_route.dart';
import 'home_page.dart';
void main() {
Request.initialize();
runApp(MedicineApp());
if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}
class MedicineApp extends StatefulWidget {
@override
State<MedicineApp> createState() => _MedicineAppState();
}
class _MedicineAppState extends State<MedicineApp> {
final _pageList = [
HomePage(),
MinePage(),
];
final _pageViewController = PageController();
int _currentPageIndex = 0;
void _bottomAppBarTap(index) {
setState(() {
_currentPageIndex = index;
});
_pageViewController.animateToPage(index, duration: Duration(milliseconds: 300), curve: Curves.ease);
}
Color _bottomAppBarItemColor(int index, BuildContext context) {
return _currentPageIndex == index ? Theme.of(context).selectedRowColor : Theme.of(context).unselectedWidgetColor;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '中药识别',
home: Scaffold(
body: PageView(
physics: NeverScrollableScrollPhysics(),
children: _pageList,
controller: _pageViewController,
),
floatingActionButton: Builder(
builder: (BuildContext context) {
return SizedBox(
width: 48,
height: 48,
child: FloatingActionButton(
backgroundColor: Theme.of(context).selectedRowColor,
onPressed: () async {
final ImagePicker _picker = ImagePicker();
final XFile? picture =
await _picker.pickImage(source: ImageSource.camera, maxHeight: 299, maxWidth: 299);
if (picture != null) {
Navigator.push(
context,
SlidePageRoute(
builder: PredictionListPage(path: picture.path),
),
);
} else {
Fluttertoast.showToast(
msg: "取消上传",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Theme.of(context).unselectedWidgetColor,
textColor: Colors.white,
fontSize: 13,
);
}
},
child: Icon(
Icons.photo_camera,
color: Colors.white70,
),
),
);
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Container(
height: 55,
child: BottomAppBar(
color: Colors.grey.shade50,
elevation: 6,
shape: CircularNotchedRectangle(),
child: Builder(
builder: (BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 2,
child: GestureDetector(
onTap: () => _bottomAppBarTap(0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
_currentPageIndex == 0 ? Icons.home_rounded : Icons.home_outlined,
color: _bottomAppBarItemColor(0, context),
),
Text(
"首页",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w500,
color: _bottomAppBarItemColor(0, context)),
),
],
),
)),
Expanded(flex: 1, child: Container()),
Expanded(
flex: 2,
child: GestureDetector(
onTap: () => _bottomAppBarTap(1),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
_currentPageIndex == 1 ? Icons.person_rounded : Icons.person_outline_rounded,
color: _bottomAppBarItemColor(1, context),
),
Text(
"我的",
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.w500, color: _bottomAppBarItemColor(1, context)),
)
],
),
),
)
],
);
},
),
),
),
),
theme: Theme.of(context).copyWith(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
primaryColor: Colors.deepOrange,
primaryColorLight: Colors.white,
primaryColorDark: Colors.black87,
accentColor: Colors.deepOrange[400]?.withAlpha(224),
selectedRowColor: Colors.deepOrangeAccent[700]),
);
}
}
bool isDebug() {
return kDebugMode;
}

@ -0,0 +1,115 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:medicine_app/request_util.dart';
class MedicineDetailPage extends StatefulWidget {
final String _name;
MedicineDetailPage({Key? key, required String name})
: _name = name,
super(key: key);
@override
_MedicineDetailPageState createState() => _MedicineDetailPageState();
}
class _MedicineDetailPageState extends State<MedicineDetailPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
color: Colors.black,
icon: Icon(Icons.arrow_back_ios),
iconSize: 18,
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: Colors.white,
centerTitle: true,
elevation: 0.4,
toolbarHeight: 55,
title: Text(
widget._name,
style: TextStyle(color: Colors.black, fontSize: 16),
),
),
body: FutureBuilder(
future: Future.sync(() async {
final response = await Request.getDio().get('/medicine/details', queryParameters: {'name': widget._name});
return response.data['data'] as Map<String, dynamic>;
}),
builder: (BuildContext context, AsyncSnapshot<Map<String, dynamic>> snapshot) {
final entries =
snapshot.data?.entries.where((element) => element.key != '_id' && element.key != 'img').toList();
if (snapshot.connectionState == ConnectionState.done) {
final maxLength = entries?.length ?? 0;
return ListView.separated(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 25),
itemBuilder: (BuildContext context, int index) {
if (index == 0 && snapshot.data?['img'] != null) {
return FractionallySizedBox(
widthFactor: 0.9,
child: ClipRRect(child: Image.network(snapshot.data?['img'])),
);
}
if (index < maxLength) {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.workspaces_filled,
color: Theme.of(context).primaryColor,
size: 12,
),
Container(
padding: EdgeInsets.only(left: 5),
child: Text(
entries?[index].key ?? '',
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
),
),
],
),
RichText(
textAlign: TextAlign.left,
text: TextSpan(
text: entries?[index].value.toString() ?? '',
style: TextStyle(color: Colors.black87, fontSize: 14, height: 3))),
],
),
);
} else {
return Center(
child: Text(
'- 没有更多了 -',
style: TextStyle(color: Colors.grey, height: 2.5),
),
);
}
},
separatorBuilder: (_, int index) {
if (index == 0 || index == maxLength - 1) {
return SizedBox.shrink();
} else {
return Divider(
height: 0.8, color: Theme.of(context).primaryColor.withAlpha(120));
}
},
itemCount: maxLength + 1);
} else {
return Center(
child: SpinKitFadingCircle(
color: Theme.of(context).primaryColor,
size: 35,
));
}
},
),
);
}
}

@ -0,0 +1,128 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
class MinePage extends StatefulWidget {
MinePage({Key? key}) : super(key: key);
@override
_MinePageState createState() => _MinePageState();
}
class _MinePageState extends State<MinePage> {
Container _menuListItem(String title, IconData iconData, Function? callback) {
final _textStyle =
TextStyle(color: Theme.of(context).primaryColorDark.withAlpha(160), fontSize: 15, fontWeight: FontWeight.w500);
return Container(
height: 55,
child: GestureDetector(
onTap: () => Fluttertoast.showToast(
msg: "开发ing",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Theme.of(context).unselectedWidgetColor,
textColor: Colors.white,
fontSize: 12,
),
child: Row(
children: [
Expanded(
flex: 1,
child: Icon(
iconData,
size: 20,
color: Theme.of(context).accentColor,
)),
Expanded(
flex: 5,
child: Text(
title,
style: _textStyle,
)),
Expanded(
flex: 1,
child: Icon(
Icons.chevron_right,
color: Colors.grey.shade400,
size: 18,
)),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).accentColor,
centerTitle: true,
elevation: 0,
toolbarHeight: 55,
title: Text(
"个人中心",
style: TextStyle(color: Colors.black, fontSize: 16),
),
),
body: Container(
child: Column(
children: [
Container(
width: double.infinity,
height: 150,
alignment: Alignment.center,
color: Theme.of(context).accentColor,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Icon(
Icons.account_circle_sharp,
size: 50,
color: Colors.black87,
),
TextButton(
onPressed: () => {},
child: Text(
'点击登录',
style: TextStyle(color: Colors.black87),
),
style: ButtonStyle(overlayColor: MaterialStateProperty.all(Colors.transparent)),
),
],
),
),
ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 10),
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
switch (index) {
case 0:
return _menuListItem('历史记录', Icons.timelapse_outlined, null);
case 1:
return _menuListItem('中药问答', Icons.question_answer, null);
case 2:
return _menuListItem('方剂智能推荐', Icons.account_tree_rounded, null);
case 3:
return _menuListItem('收藏', Icons.add_to_photos, null);
case 4:
return _menuListItem('关于', Icons.info, null);
case 5:
return _menuListItem('分享', Icons.share, null);
default:
return Container();
}
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 10, endIndent: 10, height: 0.5, color: Theme.of(context).accentColor.withAlpha(80));
},
itemCount: 6),
],
),
),
);
}
}

@ -0,0 +1,115 @@
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:medicine_app/medicine_detail_page.dart';
import 'package:medicine_app/request_util.dart';
import 'package:medicine_app/slide_page_route.dart';
class PredictionListPage extends StatefulWidget {
final String _path;
PredictionListPage({Key? key, required String path})
: _path = path,
super(key: key);
@override
_PredictionListPageState createState() => _PredictionListPageState();
}
class _PredictionListPageState extends State<PredictionListPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
color: Colors.black,
icon: Icon(Icons.arrow_back_ios),
iconSize: 18,
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: Colors.white,
centerTitle: true,
elevation: 0.4,
toolbarHeight: 55,
title: Text(
"预测",
style: TextStyle(color: Colors.black, fontSize: 17),
),
),
body: FutureBuilder(
future: Future.sync(() async {
final FormData formData = FormData.fromMap({"picture": await MultipartFile.fromFile(widget._path)});
final response = await Request.getDio().post('/medicine/prediction', data: formData);
return response.data['data'] as Map<String, dynamic>;
}),
builder: (BuildContext context, AsyncSnapshot<Map<String, dynamic>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
final entries = snapshot.data?.entries.toList().sublist(0, 14);
final maxLength = entries?.length ?? 0;
return ListView.separated(
padding: EdgeInsets.symmetric(vertical: 10),
itemBuilder: (BuildContext context, int index) {
if (index < maxLength) {
return InkWell(
splashColor: Colors.grey.shade300,
onTap: () {
Navigator.of(context).push(SlidePageRoute(
builder: MedicineDetailPage(name: "${entries?[index].key}"),
));
},
child: Container(
height: 65,
child: Row(
children: [
Expanded(
flex: 2,
child: Icon(
Icons.wallpaper_rounded,
color: Theme.of(context).primaryColor,
)),
Expanded(
flex: 3,
child: Text(
'${entries?[index].key}',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
)),
Expanded(flex: 3, child: Text('置信度:${((entries?[index].value) * 100).toStringAsFixed(2)}%')),
Expanded(
flex: 1,
child: Icon(
Icons.chevron_right,
size: 18,
color: Theme.of(context).primaryColor,
)),
],
),
),
);
} else {
return Center(
child: Text(
'- 没有更多了 -',
style: TextStyle(color: Colors.grey, height: 2.5),
),
);
}
},
itemCount: maxLength + 1,
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 25, endIndent: 20, height: 0.5, color: Theme.of(context).primaryColor.withAlpha(80));
},
);
} else {
return Center(
child: SpinKitFadingCircle(
color: Theme.of(context).primaryColor,
size: 35,
));
}
},
),
);
}
}

@ -0,0 +1,30 @@
import 'package:dio/dio.dart';
import 'main.dart';
class Request {
static late final Dio _dio;
static Dio getDio() {
return _dio;
}
static void initialize() {
final options;
if (isDebug()) {
options = BaseOptions(
baseUrl: 'http://10.10.11.253:1433',
// baseUrl: 'http://210.16.189.8:21433',
connectTimeout: 5000,
receiveTimeout: 3000,
);
} else {
options = BaseOptions(
baseUrl: 'http://210.16.189.8:21433',
connectTimeout: 5000,
receiveTimeout: 3000,
);
}
_dio = Dio(options);
}
}

@ -0,0 +1,156 @@
import 'dart:ffi';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:medicine_app/request_util.dart';
import 'package:medicine_app/slide_page_route.dart';
import 'medicine_detail_page.dart';
class SearchMedicinePage extends StatefulWidget {
SearchMedicinePage({Key? key}) : super(key: key);
@override
_SearchMedicinePageState createState() => _SearchMedicinePageState();
}
class _SearchMedicinePageState extends State<SearchMedicinePage> {
Future? _responseFuture = Future.value();
final _textEditingController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
color: Colors.black,
icon: Icon(Icons.arrow_back_ios),
iconSize: 18,
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: Colors.white,
elevation: 0.4,
titleSpacing: 0,
toolbarHeight: 55,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Container(
height: 32,
child: TextField(
autofocus: false,
controller: _textEditingController,
style: TextStyle(fontSize: 15),
cursorColor: Theme.of(context).primaryColor,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.close_rounded, size: 17),
color: Theme.of(context).primaryColor,
onPressed: () => _textEditingController.clear(),
),
contentPadding: EdgeInsets.zero,
focusColor: Theme.of(context).primaryColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 1,
)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 1,
)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 1,
)),
prefixIcon: Icon(
Icons.search_rounded,
color: Theme.of(context).primaryColor,
),
hintText: "请输入中药名",
hintStyle: TextStyle(fontSize: 14, color: Colors.grey.shade500),
),
),
),
flex: 5,
),
Expanded(
child: TextButton(
onPressed: () async {
var response = await Request.getDio()
.get('/medicine/details', queryParameters: {'keyword': _textEditingController.text});
var data = response.data['data'] as List<dynamic>;
setState(() {
_responseFuture = Future.value(data);
});
},
child: Text('搜索'),
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
foregroundColor: MaterialStateProperty.all(Theme.of(context).primaryColor)),
),
flex: 1,
)
],
),
),
body: FutureBuilder(
future: _responseFuture ?? null,
builder: (BuildContext context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
List? data = snapshot.data as List?;
if (data == null || data.length == 0) {
return Center(
child: Text('暂无结果'),
);
}
return ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 15),
itemBuilder: (BuildContext context, int index) {
var item = data[index];
var medicineItem =
item.entries.where((element) => (element.key != 'name' && element.key != 'nameSource')).toList();
return GestureDetector(
onTap: () {
Navigator.of(context).push(SlidePageRoute(
builder: MedicineDetailPage(name: "${item['nameSource']}"),
));
},
child: Html(
data: '''<div>
<h4>${item['nameSource']}</h4>
<ul>
${medicineItem.map((e) {
return "<li><p>${e.key}</p><p>${e.value}</p></li>";
}).join()}
</ul>
<!--You can pretty much put any html in here!-->
</div>''',
),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 10, endIndent: 10, height: 0.8, color: Theme.of(context).primaryColor.withAlpha(80));
},
itemCount: data.length,
);
} else {
return SpinKitFadingCircle(
color: Theme.of(context).primaryColor,
size: 32,
);
}
}),
);
}
}

@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
class SlidePageRoute extends PageRouteBuilder {
SlidePageRoute({required builder})
: super(
pageBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,) {
return builder;
},
transitionsBuilder: (BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,) {
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(1, 0),
end: Offset.zero,
).animate(animation),
child: child,
);
}
);
}

@ -0,0 +1,83 @@
name: medicine_app
description: 中药识别APP
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
image_picker:
dio:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
smooth_page_indicator: ^0.3.0-nullsafety.0
flutter_spinkit: ^5.0.0
fluttertoast: ^8.0.7
flutter_html: ^2.1.1
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

@ -0,0 +1,30 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:medicine_app/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MedicineApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save