Skip to content

Commit

Permalink
Config GitHub Action for Firebase Hosting deployment (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
banghuazhao authored Oct 13, 2024
1 parent 2cb4c25 commit 8857636
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 26 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/firebase-hosting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- main # Trigger on pushes to the main branch. Change this as needed.
pull_request: # Temporarily use it to test
branches:
- main

jobs:
build:
Expand All @@ -18,15 +21,26 @@ jobs:
with:
flutter-version: '3.19.0'

- name: Clean build
run: flutter clean

- name: Install dependencies
run: flutter pub get

- name: Set environment variables
run: |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "AMPLIFY_CONFIG=${{ secrets.AMPLIFY_CONFIG }}" >> .env
- name: Build Flutter Web
run: flutter build web

- name: Deploy to Firebase Hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
run: |
npm install -g firebase-tools
firebase deploy --only hosting --project composites-ai
# The web gives error GET https://composites-ai.web.app/assets/.env 404 (Not Found)
# Let's use local deploy for now
# TODO: fix the web error for Deploy to Firebase Hosting
# - name: Deploy to Firebase Hosting
# env:
# FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
# run: |
# npm install -g firebase-tools
# firebase deploy
5 changes: 5 additions & 0 deletions .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
with:
flutter-version: '3.19.0' # Specify Flutter version >= 3.19.0

- name: Set environment variables
run: |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "AMPLIFY_CONFIG=${{ secrets.AMPLIFY_CONFIG }}" >> .env
# Run flutter pub get to fetch dependencies
- name: Install Dependencies
run: flutter pub get
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ android/fastlane/report.xml
ios/fastlane/report.xml
.firebase
key
.env
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

SwiftComp-flutter is a mobile application designed to provide a comprehensive composite calculator based on the SwiftComp software, an efficient multiscale modeling tool for composites. The app is available on both the App Store and Google Play Store, making it accessible to a wide range of users.

## Features
## Features

- **Lamina Stress/Strain:** Calculate stress and strain for lamina layers.
- **Lamina Engineering Constants:** Determine the engineering constants for individual lamina.
Expand All @@ -17,20 +17,50 @@ SwiftComp-flutter is a mobile application designed to provide a comprehensive co
- **UDFRC Properties:** Calculate the properties for user-defined fiber-reinforced composites (UDFRC).
- **Chat (Coming Soon):** A built-in AI expert chat feature is currently under development.

## Requirements
## 📋 Requirements

- Dart: >=3.3.0 <4.0.0
- Flutter: >=3.19.0

## Installation
## 📲 Installation Guide

### Prerequisites
Make sure you have Flutter installed on your system. You can follow the official Flutter [installation guide](https://flutter.dev/docs/get-started/install) if you haven’t done so already.
Please install Flutter `3.19.0`

1. **Clone the Repository**
```bash
git clone https://github.com/banghuazhaoswiftcomp-flutter.git
cd swiftcomp-flutter
```

2. **Install Dependencies** Install the necessary Flutter dependencies by running:
```bash
flutter pub get
```

3. **Set Up Environment Variables** Create a `.env` file in the root directory and add the necessary environment variables. For example:
```
OPENAI_API_KEY=your_openai_api_key
AMPLIFY_CONFIG=your_amplify_config_json
```

4. **Run the Application**
```bash
flutter run
```
Then choose your device, it could be iOS, Android, or web.


## ⬇️ Download

### iOS
Download SwiftComp from the [App Store](https://apps.apple.com/us/app/swiftcomp-composite-calculator/id1297825946).

### Android
Download SwiftComp from the [Google Play Store](https://play.google.com/store/apps/details?id=com.banghuazhao.swiftcomp&hl=en_US).

## Screenshots
## 🖼️ Screenshots

<p align="center">
<img src="./sreenshots/sc1.webp" alt="iOS Screenshot" width="200">
Expand All @@ -39,16 +69,16 @@ Download SwiftComp from the [Google Play Store](https://play.google.com/store/ap
</p>


## Usage
## 🚀 Usage

1. **Select a Material:** Choose from the existing material database or add a new material.
2. **Input Parameters:** Enter the necessary parameters for your composite material.
3. **Calculate:** Press the calculate button to obtain results.
4. **View Results:** The app provides detailed information on the composite's properties.
5. **Chat:** A built-in AI expert chat feature is currently under development.

## Contributing
## 🤝 Contributing
Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) before submitting a pull request.

## License
## 📄 License
SwiftComp-flutter is released under the MIT License. See [LICENSE](LICENSE) for details.
Binary file removed Untitled.sketch
Binary file not shown.
12 changes: 7 additions & 5 deletions composite_calculator/lib/utils/layup_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,33 @@ class LayupParser {
if (angle == null) {
return null;
}
layups!.add(angle);
layups?.add(angle);
}

var layupsTemp = [...layups!];

for (var i = 1; i < rBefore; i++) {
for (var layup in layupsTemp) {
layups!.add(layup);
layups?.add(layup);
}
}

layupsTemp = [...layups!];
if (layups != null) {
layupsTemp = [...layups];
}

if (symmetry) {
var layupsTempReversed = layupsTemp.reversed;
for (var layup in layupsTempReversed) {
layups!.add(layup);
layups?.add(layup);
}
}

layupsTemp = [...layups!];

for (var i = 1; i < rAfter; i++) {
for (var layup in layupsTemp) {
layups!.add(layup);
layups?.add(layup);
}
}
return layups;
Expand Down
4 changes: 2 additions & 2 deletions data/lib/utils/api_constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'chat_config.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';

class ApiConstants {
static const String baseUrl = 'https://api.openai.com/v1';
static const String chatCompletionsEndpoint = '$baseUrl/chat/completions';
static String apiKey = ChatConfig.apiKey;
static String apiKey = dotenv.env['OPENAI_API_KEY'] ?? "";
}
1 change: 1 addition & 0 deletions data/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
flutter_dotenv: ^5.0.2



Expand Down
Binary file removed instant face.sketch
Binary file not shown.
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:swiftcomp/generated/l10n.dart';
Expand All @@ -11,13 +12,14 @@ import 'package:swiftcomp/util/in_app_reviewer_helper.dart';
import 'package:swiftcomp/util/others.dart';
import 'package:app_tracking_transparency/app_tracking_transparency.dart';

import 'amplifyconfiguration.dart';
import 'presentation/bottom_navigator.dart';
import 'injection_container.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await dotenv.load();

Future.delayed(Duration(seconds: 1), () {
AppTrackingTransparency.requestTrackingAuthorization();
});
Expand All @@ -27,6 +29,7 @@ void main() async {
await SharedPreferencesHelper.init();

initInjection();

runApp(MyApp());
}

Expand All @@ -44,6 +47,7 @@ class _MyAppState extends State<MyApp> {
await Amplify.addPlugin(AmplifyAuthCognito());

// call Amplify.configure to use the initialized categories in your app
final amplifyconfig = dotenv.env['AMPLIFY_CONFIG'] ?? "";
await Amplify.configure(amplifyconfig);
} on Exception catch (e) {
print('An error occurred configuring Amplify: $e');
Expand Down
5 changes: 4 additions & 1 deletion lib/presentation/chat/views/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class ChatScreen extends StatefulWidget {
State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
class _ChatScreenState extends State<ChatScreen> with AutomaticKeepAliveClientMixin{
@override
bool get wantKeepAlive => true;

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
Expand Down
8 changes: 4 additions & 4 deletions lib/presentation/tools/model/layup_sequence_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class LayupSequence {
layups = null;
return;
}
layups!.add(angle);
layups?.add(angle);
}

var layupsTemp = [...layups!];

for (var i = 1; i < rBefore; i++) {
for (var layup in layupsTemp) {
layups!.add(layup);
layups?.add(layup);
}
}

Expand All @@ -77,15 +77,15 @@ class LayupSequence {
if (symmetry) {
var layupsTempReversed = layupsTemp.reversed;
for (var layup in layupsTempReversed) {
layups!.add(layup);
layups?.add(layup);
}
}

layupsTemp = [...layups!];

for (var i = 1; i < rAfter; i++) {
for (var layup in layupsTemp) {
layups!.add(layup);
layups?.add(layup);
}
}
if (kDebugMode) {
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_dotenv:
dependency: "direct main"
description:
name: flutter_dotenv
sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
file: ^6.1.4
flutter_markdown: ^0.7.3+2
get_it: ^8.0.0
flutter_dotenv: ^5.0.2

amplify_flutter: ^1.8.0
amplify_auth_cognito: ^1.8.0
Expand Down Expand Up @@ -85,6 +86,7 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- images/
- .env

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
Expand Down

0 comments on commit 8857636

Please sign in to comment.