Compare commits
5
Commits
latest
..
e2fe4ce6c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2fe4ce6c4 | ||
|
|
cfb68fd8bb | ||
|
|
9fd2b2aa4b | ||
|
|
2854afdd22 | ||
|
|
02c8189ada |
+22
-124
@@ -18,81 +18,24 @@ jobs:
|
|||||||
build-android:
|
build-android:
|
||||||
name: Build Release APKs
|
name: Build Release APKs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/cirruslabs/flutter:3.19.3
|
image: ghcr.io/cirruslabs/flutter:3.19.3
|
||||||
options: --privileged
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Node.js 20 & ARM64 Flutter Engine
|
|
||||||
run: |
|
|
||||||
ARCH=$(uname -m)
|
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then NODE_ARCH="arm64"; else NODE_ARCH="x64"; fi
|
|
||||||
curl -fsSL "https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-${NODE_ARCH}.tar.gz" | tar -xzf - -C /usr/local --strip-components=1
|
|
||||||
node --version
|
|
||||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
||||||
git config --global --add safe.directory '*'
|
|
||||||
|
|
||||||
# On Linux ARM64, Flutter engine and Android AAPT2 need x86_64 emulation via QEMU.
|
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
||||||
echo "Setting up ARM64 Flutter environment & QEMU binfmt emulation..."
|
|
||||||
apt-get update -qq && apt-get install -y -qq qemu-user-static binfmt-support libc6-amd64-cross libstdc++6-amd64-cross gcc
|
|
||||||
|
|
||||||
# Setup x86_64 dynamic libraries & prefix for QEMU emulation
|
|
||||||
mkdir -p /etc/qemu-binfmt
|
|
||||||
ln -sf /usr/x86_64-linux-gnu /etc/qemu-binfmt/x86_64
|
|
||||||
mkdir -p /lib64 /usr/lib64
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/* /lib64/ 2>/dev/null || true
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/* /usr/lib64/ 2>/dev/null || true
|
|
||||||
|
|
||||||
export QEMU_LD_PREFIX=/usr/x86_64-linux-gnu
|
|
||||||
echo "QEMU_LD_PREFIX=/usr/x86_64-linux-gnu" >> "$GITHUB_ENV"
|
|
||||||
|
|
||||||
QEMU_BIN=$(command -v qemu-x86_64-static || command -v qemu-x86_64)
|
|
||||||
|
|
||||||
# Dummy fallbacks for FEX binaries/sockets
|
|
||||||
for fex in /usr/bin/FEXInterpreter /usr/bin/FEX /usr/local/bin/FEXInterpreter /usr/bin/FEXServer /usr/local/bin/FEXServer; do
|
|
||||||
printf '#!/bin/sh\nexit 0\n' > "$fex"
|
|
||||||
chmod +x "$fex" 2>/dev/null || true
|
|
||||||
done
|
|
||||||
|
|
||||||
flutter precache --android
|
|
||||||
for dir in /sdks/flutter/bin/cache/artifacts/engine/android-*; do
|
|
||||||
if [ -d "$dir/linux-x64" ]; then
|
|
||||||
mkdir -p "$dir/linux-arm64"
|
|
||||||
printf '#!/bin/sh\nSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"\nexec %s -L /usr/x86_64-linux-gnu "$SCRIPT_DIR/../linux-x64/gen_snapshot" "$@"\n' "$QEMU_BIN" > "$dir/linux-arm64/gen_snapshot"
|
|
||||||
chmod +x "$dir/linux-arm64/gen_snapshot"
|
|
||||||
echo "Configured gen_snapshot wrapper for $(basename "$dir")"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup QEMU Interceptor
|
- name: Configure Git Safe Directory
|
||||||
run: |
|
run: |
|
||||||
ARCH=$(uname -m)
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
git config --global --add safe.directory '*'
|
||||||
echo "Compiling transparent QEMU execution interceptor..."
|
|
||||||
gcc -O2 -shared -fPIC -o /usr/local/lib/libqemu_intercept.so scripts/ci/qemu_intercept.c -ldl
|
|
||||||
echo "LD_PRELOAD=/usr/local/lib/libqemu_intercept.so" >> "$GITHUB_ENV"
|
|
||||||
rm -f /etc/ld.so.preload
|
|
||||||
echo "Enabled LD_PRELOAD interceptor via GITHUB_ENV"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Make Gradlew Executable
|
- name: Make Gradlew Executable
|
||||||
run: |
|
run: chmod +x android/gradlew
|
||||||
if [ -f android/gradlew ]; then
|
|
||||||
chmod +x android/gradlew
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Inspect Build Environment
|
- name: Inspect Build Environment
|
||||||
run: |
|
run: |
|
||||||
flutter --version
|
flutter --version
|
||||||
java -version
|
java -version
|
||||||
node --version
|
|
||||||
|
|
||||||
- name: Fetch Flutter Dependencies
|
- name: Fetch Flutter Dependencies
|
||||||
run: flutter pub get
|
run: flutter pub get
|
||||||
@@ -103,79 +46,34 @@ jobs:
|
|||||||
flutter test
|
flutter test
|
||||||
|
|
||||||
- name: Build Universal Release APK
|
- name: Build Universal Release APK
|
||||||
run: |
|
run: flutter build apk --release
|
||||||
flutter build apk --release || {
|
|
||||||
echo "Checking if APK was built despite path mismatch..."
|
|
||||||
find build android -type f -name "*release*.apk" 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Build Split-per-ABI Release APKs
|
- name: Build Split-per-ABI Release APKs
|
||||||
run: |
|
run: flutter build apk --release --split-per-abi
|
||||||
flutter build apk --release --split-per-abi || {
|
|
||||||
echo "Checking if split APKs were built despite path mismatch..."
|
|
||||||
find build android -type f -name "*release*.apk" 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Organize Artifacts
|
- name: Organize Artifacts
|
||||||
run: |
|
run: |
|
||||||
mkdir -p release-apks
|
mkdir -p release-apks
|
||||||
# Copy universal APK
|
# Copy universal APK
|
||||||
if [ -f build/app/outputs/flutter-apk/app-release.apk ]; then
|
if [ -f build/app/outputs/flutter-apk/app-release.apk ]; then
|
||||||
cp build/app/outputs/flutter-apk/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
cp build/app/outputs/flutter-apk/app-release.apk release-apks/oggauer-gemeindetrommler-universal-release.apk
|
||||||
elif [ -f android/app/build/outputs/apk/release/app-release.apk ]; then
|
|
||||||
cp android/app/build/outputs/apk/release/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
|
||||||
fi
|
fi
|
||||||
# Copy split APKs
|
# Copy split APKs
|
||||||
for apk in build/app/outputs/flutter-apk/*.apk android/app/build/outputs/apk/release/*.apk; do
|
if [ -f build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ]; then
|
||||||
[ -f "$apk" ] || continue
|
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
||||||
case "$(basename "$apk")" in
|
fi
|
||||||
*arm64-v8a*) cp "$apk" release-apks/oggauer-gemeindetrommler-arm64-v8a.apk ;;
|
if [ -f build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk ]; then
|
||||||
*armeabi-v7a*) cp "$apk" release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk ;;
|
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
||||||
*x86_64*) cp "$apk" release-apks/oggauer-gemeindetrommler-x86_64.apk ;;
|
fi
|
||||||
esac
|
if [ -f build/app/outputs/flutter-apk/app-x86_64-release.apk ]; then
|
||||||
done
|
cp build/app/outputs/flutter-apk/app-x86_64-release.apk release-apks/oggauer-gemeindetrommler-x86_64.apk
|
||||||
echo "=== Generated All 4 APK Artifacts ==="
|
fi
|
||||||
|
echo "=== Generated APK Artifacts ==="
|
||||||
ls -lah release-apks/
|
ls -lah release-apks/
|
||||||
|
|
||||||
- name: Upload Universal APK
|
- name: Upload APKs to Gitea Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: oggauer-gemeindetrommler-universal
|
name: oggauer-gemeindetrommler-apks
|
||||||
path: release-apks/oggauer-gemeindetrommler-universal.apk
|
path: release-apks/*.apk
|
||||||
retention-days: 7
|
retention-days: 30
|
||||||
|
|
||||||
- name: Upload ARM64 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-arm64-v8a
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Upload ARMv7 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-armeabi-v7a
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Upload x86_64 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-x86_64
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-x86_64.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Publish Direct APKs to Gitea Releases
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
GITEA_API: ${{ github.api_url }}
|
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
RELEASE_TAG: latest
|
|
||||||
run: |
|
|
||||||
node scripts/ci/publish_release.js
|
|
||||||
|
|
||||||
- name: Clean Workspace Disk Space
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
rm -rf build android/.gradle release-apks 2>/dev/null || true
|
|
||||||
|
|||||||
@@ -18,81 +18,24 @@ jobs:
|
|||||||
build-android:
|
build-android:
|
||||||
name: Build Release APKs
|
name: Build Release APKs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/cirruslabs/flutter:3.19.3
|
image: ghcr.io/cirruslabs/flutter:3.19.3
|
||||||
options: --privileged
|
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Node.js 20 & ARM64 Flutter Engine
|
|
||||||
run: |
|
|
||||||
ARCH=$(uname -m)
|
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then NODE_ARCH="arm64"; else NODE_ARCH="x64"; fi
|
|
||||||
curl -fsSL "https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-${NODE_ARCH}.tar.gz" | tar -xzf - -C /usr/local --strip-components=1
|
|
||||||
node --version
|
|
||||||
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
||||||
git config --global --add safe.directory '*'
|
|
||||||
|
|
||||||
# On Linux ARM64, Flutter engine and Android AAPT2 need x86_64 emulation via QEMU.
|
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
||||||
echo "Setting up ARM64 Flutter environment & QEMU binfmt emulation..."
|
|
||||||
apt-get update -qq && apt-get install -y -qq qemu-user-static binfmt-support libc6-amd64-cross libstdc++6-amd64-cross gcc
|
|
||||||
|
|
||||||
# Setup x86_64 dynamic libraries & prefix for QEMU emulation
|
|
||||||
mkdir -p /etc/qemu-binfmt
|
|
||||||
ln -sf /usr/x86_64-linux-gnu /etc/qemu-binfmt/x86_64
|
|
||||||
mkdir -p /lib64 /usr/lib64
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/* /lib64/ 2>/dev/null || true
|
|
||||||
ln -sf /usr/x86_64-linux-gnu/lib/* /usr/lib64/ 2>/dev/null || true
|
|
||||||
|
|
||||||
export QEMU_LD_PREFIX=/usr/x86_64-linux-gnu
|
|
||||||
echo "QEMU_LD_PREFIX=/usr/x86_64-linux-gnu" >> "$GITHUB_ENV"
|
|
||||||
|
|
||||||
QEMU_BIN=$(command -v qemu-x86_64-static || command -v qemu-x86_64)
|
|
||||||
|
|
||||||
# Dummy fallbacks for FEX binaries/sockets
|
|
||||||
for fex in /usr/bin/FEXInterpreter /usr/bin/FEX /usr/local/bin/FEXInterpreter /usr/bin/FEXServer /usr/local/bin/FEXServer; do
|
|
||||||
printf '#!/bin/sh\nexit 0\n' > "$fex"
|
|
||||||
chmod +x "$fex" 2>/dev/null || true
|
|
||||||
done
|
|
||||||
|
|
||||||
flutter precache --android
|
|
||||||
for dir in /sdks/flutter/bin/cache/artifacts/engine/android-*; do
|
|
||||||
if [ -d "$dir/linux-x64" ]; then
|
|
||||||
mkdir -p "$dir/linux-arm64"
|
|
||||||
printf '#!/bin/sh\nSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"\nexec %s -L /usr/x86_64-linux-gnu "$SCRIPT_DIR/../linux-x64/gen_snapshot" "$@"\n' "$QEMU_BIN" > "$dir/linux-arm64/gen_snapshot"
|
|
||||||
chmod +x "$dir/linux-arm64/gen_snapshot"
|
|
||||||
echo "Configured gen_snapshot wrapper for $(basename "$dir")"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup QEMU Interceptor
|
- name: Configure Git Safe Directory
|
||||||
run: |
|
run: |
|
||||||
ARCH=$(uname -m)
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
git config --global --add safe.directory '*'
|
||||||
echo "Compiling transparent QEMU execution interceptor..."
|
|
||||||
gcc -O2 -shared -fPIC -o /usr/local/lib/libqemu_intercept.so scripts/ci/qemu_intercept.c -ldl
|
|
||||||
echo "LD_PRELOAD=/usr/local/lib/libqemu_intercept.so" >> "$GITHUB_ENV"
|
|
||||||
rm -f /etc/ld.so.preload
|
|
||||||
echo "Enabled LD_PRELOAD interceptor via GITHUB_ENV"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Make Gradlew Executable
|
- name: Make Gradlew Executable
|
||||||
run: |
|
run: chmod +x android/gradlew
|
||||||
if [ -f android/gradlew ]; then
|
|
||||||
chmod +x android/gradlew
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Inspect Build Environment
|
- name: Inspect Build Environment
|
||||||
run: |
|
run: |
|
||||||
flutter --version
|
flutter --version
|
||||||
java -version
|
java -version
|
||||||
node --version
|
|
||||||
|
|
||||||
- name: Fetch Flutter Dependencies
|
- name: Fetch Flutter Dependencies
|
||||||
run: flutter pub get
|
run: flutter pub get
|
||||||
@@ -103,69 +46,34 @@ jobs:
|
|||||||
flutter test
|
flutter test
|
||||||
|
|
||||||
- name: Build Universal Release APK
|
- name: Build Universal Release APK
|
||||||
run: |
|
run: flutter build apk --release
|
||||||
flutter build apk --release || {
|
|
||||||
echo "Checking if APK was built despite path mismatch..."
|
|
||||||
find build android -type f -name "*release*.apk" 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Build Split-per-ABI Release APKs
|
- name: Build Split-per-ABI Release APKs
|
||||||
run: |
|
run: flutter build apk --release --split-per-abi
|
||||||
flutter build apk --release --split-per-abi || {
|
|
||||||
echo "Checking if split APKs were built despite path mismatch..."
|
|
||||||
find build android -type f -name "*release*.apk" 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Organize Artifacts
|
- name: Organize Artifacts
|
||||||
run: |
|
run: |
|
||||||
mkdir -p release-apks
|
mkdir -p release-apks
|
||||||
# Copy universal APK
|
# Copy universal APK
|
||||||
if [ -f build/app/outputs/flutter-apk/app-release.apk ]; then
|
if [ -f build/app/outputs/flutter-apk/app-release.apk ]; then
|
||||||
cp build/app/outputs/flutter-apk/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
cp build/app/outputs/flutter-apk/app-release.apk release-apks/oggauer-gemeindetrommler-universal-release.apk
|
||||||
elif [ -f android/app/build/outputs/apk/release/app-release.apk ]; then
|
|
||||||
cp android/app/build/outputs/apk/release/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
|
||||||
fi
|
fi
|
||||||
# Copy split APKs
|
# Copy split APKs
|
||||||
for apk in build/app/outputs/flutter-apk/*.apk android/app/build/outputs/apk/release/*.apk; do
|
if [ -f build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ]; then
|
||||||
[ -f "$apk" ] || continue
|
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
||||||
case "$(basename "$apk")" in
|
fi
|
||||||
*arm64-v8a*) cp "$apk" release-apks/oggauer-gemeindetrommler-arm64-v8a.apk ;;
|
if [ -f build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk ]; then
|
||||||
*armeabi-v7a*) cp "$apk" release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk ;;
|
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
||||||
*x86_64*) cp "$apk" release-apks/oggauer-gemeindetrommler-x86_64.apk ;;
|
fi
|
||||||
esac
|
if [ -f build/app/outputs/flutter-apk/app-x86_64-release.apk ]; then
|
||||||
done
|
cp build/app/outputs/flutter-apk/app-x86_64-release.apk release-apks/oggauer-gemeindetrommler-x86_64.apk
|
||||||
echo "=== Generated All 4 APK Artifacts ==="
|
fi
|
||||||
|
echo "=== Generated APK Artifacts ==="
|
||||||
ls -lah release-apks/
|
ls -lah release-apks/
|
||||||
|
|
||||||
- name: Upload Universal APK
|
- name: Upload APKs to Gitea Artifacts
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: oggauer-gemeindetrommler-universal
|
name: oggauer-gemeindetrommler-apks
|
||||||
path: release-apks/oggauer-gemeindetrommler-universal.apk
|
path: release-apks/*.apk
|
||||||
retention-days: 7
|
retention-days: 30
|
||||||
|
|
||||||
- name: Upload ARM64 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-arm64-v8a
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Upload ARMv7 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-armeabi-v7a
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Upload x86_64 APK
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-x86_64
|
|
||||||
path: release-apks/oggauer-gemeindetrommler-x86_64.apk
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
- name: Clean Workspace Disk Space
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
rm -rf build android/.gradle release-apks 2>/dev/null || true
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
name: Build iOS IPA
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- master
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
- 'latest'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-ios:
|
|
||||||
name: Build iOS IPA
|
|
||||||
runs-on: macos-14
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Flutter
|
|
||||||
uses: subosito/flutter-action@v2
|
|
||||||
with:
|
|
||||||
flutter-version: '3.19.3'
|
|
||||||
channel: 'stable'
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: Inspect Environment
|
|
||||||
run: |
|
|
||||||
flutter --version
|
|
||||||
xcodebuild -version
|
|
||||||
pod --version
|
|
||||||
|
|
||||||
- name: Fetch Dependencies
|
|
||||||
run: flutter pub get
|
|
||||||
|
|
||||||
- name: Install CocoaPods Pods
|
|
||||||
run: |
|
|
||||||
cd ios
|
|
||||||
pod install --repo-update
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
- name: Build iOS (Unsigned IPA)
|
|
||||||
run: |
|
|
||||||
flutter build ios --release --no-codesign
|
|
||||||
mkdir -p build/ios/iphoneos/Payload
|
|
||||||
cp -r build/ios/iphoneos/Runner.app build/ios/iphoneos/Payload/
|
|
||||||
cd build/ios/iphoneos
|
|
||||||
zip -r oggauer-gemeindetrommler.ipa Payload
|
|
||||||
|
|
||||||
- name: Upload IPA Artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: oggauer-gemeindetrommler-ios
|
|
||||||
path: build/ios/iphoneos/oggauer-gemeindetrommler.ipa
|
|
||||||
retention-days: 7
|
|
||||||
@@ -44,7 +44,3 @@ app.*.map.json
|
|||||||
/android/app/release
|
/android/app/release
|
||||||
/android/app/build/
|
/android/app/build/
|
||||||
.gradle/
|
.gradle/
|
||||||
release-apks/
|
|
||||||
gitea-runner/data/
|
|
||||||
gitea-runner/.env
|
|
||||||
backups/
|
|
||||||
|
|||||||
@@ -1,151 +1,86 @@
|
|||||||
# Oggauer Gemeindetrommler 🥁
|
# Oggauer Gemeindetrommler 🥁
|
||||||
|
|
||||||
Die **Oggauer Gemeindetrommler App** ist die offizielle Smartphone-Anwendung (Flutter für Android & iOS) des **Bürgerforums Oggau** für alle Bürgerinnen und Bürger der Marktgemeinde Oggau am Neusiedler See.
|
Die **Oggauer Gemeindetrommler App** ist eine mobile Anwendung (Flutter für Android & iOS) für Bürgerinnen und Bürger der Marktgemeinde Oggau am Neusiedler See. Sie dient als digitale Plattform für Gemeinde-Nachrichten, Bürgeranliegen (Mängelmeldungen mit Foto-Upload) sowie den Austausch im Bürgerforum bzw. die Einbringung von Gemeinde-Ideen inklusive PDF-Exportfunktionen.
|
||||||
|
|
||||||
Die App vereint aktuelle Gemeinde-Nachrichten, offizielle PDF-Aussendungen des Bürgerforums, einen bürgernahen Mängelmelder mit Foto-Upload, eine Ideenplattform sowie einen direkten Kontaktkanal mit integriertem Admin-Posteingang und vollständiger In-App-Benutzerverwaltung.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📱 Funktionsumfang & Module
|
## 📱 Aktueller Funktionsumfang (Ist-Zustand)
|
||||||
|
|
||||||
### 1. 📰 Nachrichten & Offizielle PDF-Aussendungen (`News`)
|
Die App wurde in ihrer Erstversion mit Unterstützung von KI (frühe GPT-Modelle) entwickelt und nutzt Firebase als Backend.
|
||||||
- **Chronologischer Feed:** Vereint manuell erstellte Gemeinde-Nachrichten und die offiziellen Rundschreiben/Aussendungen des Bürgerforums nach Datum sortiert (neueste zuerst).
|
|
||||||
- **WordPress REST-API Anbindung:** Vollautomatische Synchronisation der Aussendungen von [buergerforumoggau.at](https://buergerforumoggau.at/category/aktuelles/aussendungen/) inklusive HTML-Bereinigung und PDF-Extraktion.
|
|
||||||
- **Offline-First:** Geladene Aussendungen werden lokal via `SharedPreferences` zwischengespeichert und stehen sofort beim App-Start sowie offline zur Verfügung.
|
|
||||||
- **Integrierter PDF-Reader:**
|
|
||||||
- Flüssige In-App-Vorschau ohne externe App zwingend öffnen zu müssen.
|
|
||||||
- **Stufenloser Zoom:** Gesten-Zoom (Pinch-to-Zoom von 0.8x bis 5.0x) und schwebendes Bedienfeld (`+`, `-`, `1:1` Reset auf 100%).
|
|
||||||
- **Drucken & Teilen:** Direktes Teilen von PDFs via `Printing.sharePdf` und System-Druckfunktion.
|
|
||||||
- **Browser-Aufruf:** Öffnen des Original-Dokuments im Standard-Webbrowser oder externen PDF-Viewer.
|
|
||||||
- **Filter-Leiste:** Schnelles Filtern nach `Alle`, `Aussendungen (PDF)` und `Aktuelles`.
|
|
||||||
- **Echtzeitsuche & PDF-Export:** Volltextsuche in Beiträgen sowie Export von Einzelbeiträgen oder Tabellenübersichten als PDF.
|
|
||||||
- **Redaktions-Funktion:** Berechtigte Administratoren können neue Nachrichten direkt über die App mit Titel, Text und Beitragsbild erfassen.
|
|
||||||
|
|
||||||
### 2. ⚠️ Mängelmelder (`Issues`)
|
### 1. Neuigkeiten (`News`)
|
||||||
- **Mängelübersicht:** Chronologische Liste aller im Gemeindegebiet gemeldeten Mängel mit Bildvorschau, Status und Ortsangabe.
|
- Liste aktueller Berichte und Neuigkeiten aus der Gemeinde mit Datum, Überschrift, Textvorschau und Beitragsbild.
|
||||||
- **Strukturierte Erfassung:**
|
- Detailansicht mit vollständigem Text und großem Beitragsbild.
|
||||||
- Titel und detaillierte Beschreibung.
|
- PDF-Export: Sowohl Einzelbeiträge als auch eine Mehrfachauswahl können direkt als PDF generiert und geteilt werden.
|
||||||
- Kategorie-Auswahl (z. B. Straßenbeleuchtung, Straßenschäden, Grünflächen, Müll, Spielplätze).
|
|
||||||
- Pflicht-Dropdown aller offiziellen Straßen in Oggau.
|
|
||||||
- Bis zu 2 Fotos (Aufnahme direkt per Kamera oder Auswahl aus der Galerie).
|
|
||||||
- Automatische Bildkomprimierung und Speicheroptimierung (< 10 MB).
|
|
||||||
- **Status-Workflow:** Verwaltung durch Administratoren (`Gemeldet` $\rightarrow$ `In Bearbeitung` $\rightarrow$ `Behoben`).
|
|
||||||
- **Sammel-PDF-Druck:** Mehrfachauswahl gemeldeter Mängel mit tabellarischem PDF-Export (ideal zur Weiterleitung an den Bauhof oder Gemeinderat).
|
|
||||||
- **Löschfunktion:** Verfasser und Administratoren können Meldungen per Wischgeste entfernen.
|
|
||||||
|
|
||||||
### 3. 💡 BürgerForum & Ideen (`CitizensForum`)
|
### 2. Mängelübersicht & Mängelmeldung (`Issues`)
|
||||||
- Bürger-Beteiligungsplattform für Anregungen, Projektideen und Initiativen zur Dorfentwicklung.
|
- Übersicht über gemeldete Mängel im Ortsgebiet (chronologisch sortiert).
|
||||||
- Erfassung mit Titel, Freitextbeschreibung und bis zu 2 Fotos/Anhängen.
|
- Erfassung neuer Mängel mit Titel, Beschreibungstext und Foto (Kamera oder Galerie).
|
||||||
- PDF-Export und Druckunterstützung zur Vorstellung in Ausschüssen oder Sitzungen.
|
- Automatischer Zuschnitt (1:1 Quadrat) und Größenvalidierung (< 10 MB).
|
||||||
|
- Eigene Meldungen können per Wischgeste (Swipe-to-Delete) entfernt werden.
|
||||||
|
- Mehrfachauswahl von Mängeln mit Sammel-PDF-Export (z. B. zur Weiterleitung an den Bauhof).
|
||||||
|
|
||||||
### 4. 📬 Kontakt & Admin-Posteingang (`Contact`)
|
### 3. BürgerForum / Ideen (`CitizensForum`)
|
||||||
- **Bürger-Kontaktformular:**
|
- Plattform zur Einbringung von Anregungen und Vorschlägen für das Gemeindeleben.
|
||||||
- Einfache und direkte Kontaktaufnahme mit dem Bürgerforum.
|
- Nutzt aktuell den gleichen Erfassungs- und PDF-Export-Workflow wie bei den Mängeln.
|
||||||
- Pflichtangaben: Name, E-Mail-Adresse und Anliegen.
|
|
||||||
- Optionale Rückruf-Telefonnummer für schnelle Rückfragen.
|
|
||||||
- Rechtlicher Datenschutzhinweis.
|
|
||||||
- **Admin-Posteingang (`AdminMessagesScreen`):**
|
|
||||||
- Administratoren haben direkten Zugriff auf alle über die App eingesendeten Bürgernachrichten.
|
|
||||||
- **Echtzeit-Aktualisierung** via Firestore.
|
|
||||||
- **Filter-Chips:** Schnelles Filtern nach `Alle`, `Neu`, `In Bearbeitung` und `Erledigt`.
|
|
||||||
- **Volltextsuche:** Durchsucht Betreff, Nachrichtentext, Absender-Name und E-Mail-Adresse.
|
|
||||||
- **Detail-Ansicht (Bottom Sheet):**
|
|
||||||
- Vollständiger Nachrichtentext mit Metadaten und Zeitstempel.
|
|
||||||
- Statuswechsel (`Neu`, `In Bearbeitung`, `Erledigt`).
|
|
||||||
- Ein-Klick-Aktionen: Direkte E-Mail-Antwort (`mailto:`) und Anruf (`tel:`).
|
|
||||||
- Sicheres Löschen erledigter Nachrichten.
|
|
||||||
|
|
||||||
### 5. ℹ️ Bürgerforum-Info, Leitbild & In-App-Benutzerverwaltung (`Info`)
|
### 4. Authentifizierung (`AuthState`)
|
||||||
- **Leitbild & Über uns:** Informationen über die Grundsätze, Ziele und Aktivitäten des Bürgerforums Oggau.
|
- Anonyme Firebase-Authentifizierung (`FirebaseAuth.signInAnonymously`).
|
||||||
- **Notrufnummern:** Wichtige Notfallkontakte (Feuerwehr, Polizei, Rettung, Euronotruf, Vergiftungszentrale, etc.) auf einen Blick mit direkter Anruffunktion.
|
- Lesemodus für Gäste; Erstellen und Löschen eigener Beiträge ist an den angemeldeten Nutzerstatus gekoppelt.
|
||||||
- **Benutzerkonto-Status:** Transparente Anzeige des Anmeldestatus (`Gast`, `Bürger`, `Administrator`).
|
|
||||||
- **In-App-Benutzerverwaltung (`UserManagementScreen`):**
|
|
||||||
- Keine Notwendigkeit mehr, für die Rollenvergabe die Firebase Console zu öffnen.
|
|
||||||
- Vollständige Liste aller registrierten Bürger mit Such- und Filterfunktion (`Alle`, `Administratoren`, `Bürger`).
|
|
||||||
- **Admin-Rechte verwalten:** Beförderung zum Administrator oder Entzug von Admin-Rechten mit einem Klick (inklusive Sicherheits-Bestätigungsdialog).
|
|
||||||
- **Selbstentzugs-Schutz:** Der angemeldete Admin kann sich nicht versehentlich selbst die Administrationsrechte entziehen.
|
|
||||||
- **Manuelle Admin-Freischaltung:** Zusätzliche Dialog-Eingabe zur direkten Autorisierung per E-Mail oder UID.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔒 Sicherheitsarchitektur (Backend & Frontend)
|
## 🔍 Soll vs. Ist Abgleich (Original-Anforderungen)
|
||||||
|
|
||||||
Die Sicherheit und Integrität der Bürgerdaten wird durch ein mehrstufiges Sicherheitskonzept gewährleistet:
|
Basierend auf dem ursprünglichen Lastenheft von Thomas und den UI-Wireframes (`App (1).xlsx`) ergibt sich folgender Umsetzungsstatus:
|
||||||
|
|
||||||
1. **Firestore Security Rules (`firestore.rules`):**
|
| Anforderung / Modul | Ursprüngliche Spezifikation | Aktueller Umsetzungsstatus | Status |
|
||||||
- **`/Users/{userId}`:** Nutzer können ihr eigenes Profil lesen und pflegen. Nur Administratoren (`isAdmin()`) haben Vollzugriff auf alle Benutzerprofile.
|
|---|---|---|---|
|
||||||
- **`/Admins/{adminDoc}`:** Schreib- und Löschrechte sind strikt auf bestehende Administratoren beschränkt.
|
| **Startseite / News** | 2-Zeilen-Vorschau, Trennlinie, Volltextsuche (Lupe), Detailansicht, PDF/JPG-Anhänge | Überschrift, Datum, 3 Zeilen Text, Bild, Detailansicht | 🟡 Teilweise (Suche fehlt, nur 1 Bild) |
|
||||||
- **`/ContactMessages/{doc}`:** Eingereichte Kontaktanfragen können ausschließlich von Administratoren oder dem jeweiligen Verfasser gelesen werden. Statusänderungen und Löschungen sind Administratoren vorbehalten.
|
| **Mängelübersicht** | Liste, Volltextsuche, PDF-Tabellendruck einer Auswahl | Liste vorhanden, Checkbox-Auswahl + PDF-Druck integriert | 🟡 Teilweise (Suche & Tabellenlayout im PDF fehlen) |
|
||||||
- **`/News/{newsId}`:** Erstellen und Löschen von News-Beiträgen ist nur für Administratoren gestattet.
|
| **Mängelerfassung** | Pflicht-Dropdown für Straße/Ort, Dropdown für Grundlage, max. 2 Fotos im Querformat (max. 800x600), automatischer Verfasser | Titel, Beschreibung, 1 Foto im Quadrat (1:1). Keine Dropdowns | 🔴 Wesentliche Felder fehlen |
|
||||||
- **`/Issues` & `/CitizensForum`:** Angemeldete Nutzer dürfen eigene Beiträge erfassen und löschen; Admins dürfen den Bearbeitungsstatus pflegen.
|
| **Ideen** | Wie Mängel, bis zu 5 Anhänge (PDF/Bilder), kein Druck erforderlich | Als „BürgerForum“ realisiert, aber identische Maske zu Mängeln (nur 1 Bild) | 🟡 Teilweise (Mehrfach-Upload bis 5 Dateien fehlt) |
|
||||||
2. **Cloud Storage Rules (`storage.rules`):**
|
| **Kontakt** | Freitext, Name, Nachname, E-Mail (Pflicht), Rückrufnummer (optional), E-Mail-Versand, Rechtshinweis | Nicht im Menü eingebunden; nur Registrier-Fragmente vorhanden | 🔴 Fehlt komplett |
|
||||||
- Uploads sind auf angemeldete Nutzer, Dateigrößen unter 10 MB und gültige Bildformate (`image/*`) limitiert.
|
| **Information / Impressum** | Öffentliche Gemeinde-Infos, Veranstaltungen, Impressum ohne Login frei zugänglich | Nicht vorhanden | 🔴 Fehlt komplett |
|
||||||
- Fotos dürfen ausschließlich vom ursprünglichen Verfasser oder von einem berechtigten Administrator gelöscht werden.
|
| **Zugangsschutz / Auth** | Gemeindebürger-Zugang via Passwort/Freigabe; nur Info-Bereich offen | Anonymer Login per Knopfdruck für alle; Fragmente für E-Mail-Login | 🔴 Entspricht nicht dem Passwort-Konzept |
|
||||||
3. **Automatische Profil-Synchronisation:**
|
| **Design & Header** | Neutraler Hintergrund, optionales Betreiber-Logo im Header | Schlichter Material-AppBar-Header ohne Logo | 🟡 Optimierbar |
|
||||||
- Bei jeder Anmeldung oder Registrierung gleicht `AuthService` das Benutzerprofil mit Firestore (`Users/{uid}`) ab.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📊 Umsetzungsstatus (Soll vs. Ist)
|
|
||||||
|
|
||||||
| Anforderung / Modul | Spezifikation & Features | Umsetzungsstatus | Status |
|
|
||||||
|---|---|---|:---:|
|
|
||||||
| **News & Aussendungen** | Chronologischer Feed, Volltextsuche, PDF-Aussendungen der Webseite, Zoom-Viewer, PDF-Export | Vollständig integriert (WordPress REST-API, In-App Zoom Reader, Filter-Chips) | 🟢 Erledigt |
|
|
||||||
| **Mängelübersicht** | Chronologische Liste, Straßenauswahl, Volltextsuche, Tabellen-PDF-Export, Status-Tracking | Vollständig integriert (Dropdown aller Oggauer Straßen, Statusanzeige, PDF-Export) | 🟢 Erledigt |
|
|
||||||
| **Mängelerfassung** | Pflicht-Straße, Kategorie, max. 2 Fotos, automatische Komprimierung, Verfasser-Zuordnung | Vollständig integriert (Kamera/Galerie, Dual-Foto-Upload, Validierung) | 🟢 Erledigt |
|
|
||||||
| **Bürgerforum / Ideen** | Bürgerbeteiligung, Beschreibung, bis zu 2 Anhänge, PDF-Export | Vollständig integriert | 🟢 Erledigt |
|
|
||||||
| **Kontakt & Posteingang** | Kontaktformular mit Validierung, Datenschutzhinweis, Admin-Nachrichten-Posteingang | Vollständig integriert (Echtzeit-Inbox, Status-Workflow, Schnellantwort) | 🟢 Erledigt |
|
|
||||||
| **Benutzerverwaltung** | Rollenverwaltung (Admin/Bürger), Kontoverwaltung in der App ohne Firebase Console | Vollständig integriert (In-App User Management, Selbstschutz, Echtzeit) | 🟢 Erledigt |
|
|
||||||
| **Info & Notruf** | Leitbild Bürgerforum, Gemeinde-Informationen, Notfallnummern mit Schnellwahl | Vollständig integriert | 🟢 Erledigt |
|
|
||||||
| **Authentifizierung & Rechte** | E-Mail/Passwort, Bürger-Freischaltung, Rollenkonzept, Gast-Zugang, Security Rules | Vollständig integriert & backend-seitig gehärtet | 🟢 Erledigt |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🏗️ Technische Architektur & Tech-Stack
|
## 🏗️ Technische Architektur & Tech-Stack
|
||||||
|
|
||||||
### Verwendete Technologien:
|
### Verwendete Technologien:
|
||||||
- **Framework:** [Flutter](https://flutter.dev) (Dart SDK `>=3.0.0`)
|
- **Framework:** [Flutter](https://flutter.dev) (Dart SDK `>=2.18.2 <3.0.0` / Dart 3 kompatibel)
|
||||||
- **Backend & Cloud Services (Google Firebase):**
|
- **Backend / Cloud Services (Firebase):**
|
||||||
- `firebase_core` (Initialisierung)
|
- `firebase_core` (Core-Initialisierung)
|
||||||
- `firebase_auth` (E-Mail & Passwort Authentifizierung, Gast-Modus)
|
- `firebase_auth` (Authentifizierung)
|
||||||
- `cloud_firestore` (NoSQL Echtzeit-Datenbank)
|
- `cloud_firestore` (NoSQL Echtzeitdatenbank für News, Mängel, Ideen)
|
||||||
- `firebase_storage` (Cloud-Bilderspeicher)
|
- `firebase_storage` (Speicherung hochgeladener Bilder)
|
||||||
- **Externe APIs & Web-Services:**
|
- **PDF-Erstellung & Druck:** `pdf`, `printing`
|
||||||
- WordPress REST-API (`http`-Paket für Bürgerforum-Aussendungen)
|
- **Bildverarbeitung:** `image`, `image_picker`, `image_cropper`, `cached_network_image`
|
||||||
- `shared_preferences` (Offline-Zwischenspeicherung)
|
- **State Management:** `provider`
|
||||||
- **Dokumentenverarbeitung & PDF:**
|
|
||||||
- `pdf`, `printing` (PDF-Generierung, In-App Vorschau & Druck)
|
|
||||||
- `url_launcher` (System-Browser, Telefon- und E-Mail-Intents)
|
|
||||||
- **Bildverarbeitung:**
|
|
||||||
- `image_picker`, `image_cropper`, `cached_network_image`, `image`
|
|
||||||
- **State Management:**
|
|
||||||
- `provider` (`MultiProvider` Architektur)
|
|
||||||
|
|
||||||
### Projektstruktur (`lib/`):
|
### Projektstruktur (`lib/`):
|
||||||
```text
|
```text
|
||||||
lib/
|
lib/
|
||||||
├── firebase_options.dart # Firebase-Konfiguration für Android & iOS
|
├── firebase_options.dart # Firebase-Projektkonfiguration (Android & iOS)
|
||||||
├── main.dart # Einstiegspunkt, Theme & MultiProvider Setup
|
├── main.dart # App-Einstiegspunkt, Firebase Init & MultiProvider
|
||||||
├── models/
|
├── models/
|
||||||
│ └── post_item.dart # Datenmodell für News, Aussendungen, Mängel & Ideen
|
│ └── post_item.dart # Typisiertes Datenmodell für News, Mängel & Ideen
|
||||||
├── screens/
|
├── screens/
|
||||||
│ ├── add_issue_screen.dart # Mängelerfassung (Straßen-Dropdown & bis zu 2 Fotos)
|
│ ├── add_issue_screen.dart # Mängelerfassung mit Straßenauswahl & bis zu 2 Fotos
|
||||||
│ ├── add_post_screen.dart # Erfassung von News (Admins) & Bürgerideen
|
│ ├── add_post_screen.dart # Universelle Erfassung für News & Bürgerideen
|
||||||
│ ├── admin_messages_screen.dart # Admin-Posteingang für eingegangene Kontaktanfragen
|
│ ├── auth_dialog.dart # Anmelde-, Registrierungs- & Code-Freischaltungs-Dialog
|
||||||
│ ├── auth_dialog.dart # Anmelde-, Registrierungs- & Freischaltungs-Dialog
|
│ ├── contact_screen.dart # Bürgerforum-Kontaktformular & Anfragen
|
||||||
│ ├── contact_screen.dart # Bürger-Kontaktformular mit Admin-Posteingang-Banner
|
│ ├── detail_screen.dart # Detailansicht mit Metadaten & PDF-Einzelexport
|
||||||
│ ├── detail_screen.dart # Beitrags-Detailansicht mit PDF-Direktaufruf
|
│ ├── home_screen.dart # Haupt-Scaffold mit 5 Tabs (News, Mängel, Ideen, Kontakt, Info)
|
||||||
│ ├── home_screen.dart # Haupt-Navigation mit 5 Tabs
|
│ ├── info_screen.dart # Bürgerforum Leitbild, Notrufnummern & Account-Status
|
||||||
│ ├── info_screen.dart # Bürgerforum Leitbild, Notrufnummern & Kontostatus
|
│ └── post_list_screen.dart # Universelle Listenansicht, Echtzeitsuche & PDF-Tabelle
|
||||||
│ ├── pdf_viewer_screen.dart # In-App PDF-Viewer mit Pinch-to-Zoom & Schwebepanel
|
|
||||||
│ ├── post_list_screen.dart # News-, Mängel- & Ideen-Listen mit Volltextsuche & Filter
|
|
||||||
│ └── user_management_screen.dart# In-App Benutzerverwaltung & Admin-Rollenvergabe
|
|
||||||
└── services/
|
└── services/
|
||||||
├── aussendungen_service.dart # WordPress REST-API Client mit SharedPreferences-Cache
|
├── auth_service.dart # Hybrid-Auth (E-Mail/Passwort, Bürger-Code, Anonym)
|
||||||
├── auth_service.dart # Authentifizierung & automatischer Firestore-Profilabgleich
|
├── firestore_service.dart# NoSQL CRUD & Kontaktanfragen
|
||||||
├── firestore_service.dart # Firestore CRUD, Admin-Verwaltung & Kontakt-Stream
|
├── pdf_service.dart # PDF-Druckerzeugung (Listen & Einzelansichten)
|
||||||
├── pdf_service.dart # PDF-Tabellen und Einzeldokument-Erstellung
|
└── storage_service.dart # Optimierter Bild-Upload (Querformat max 800x600)
|
||||||
└── storage_service.dart # Komprimierter Cloud-Storage Bild-Upload
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -154,36 +89,44 @@ lib/
|
|||||||
|
|
||||||
Die App verfügt über eine vollautomatische Build-Pipeline für **Gitea Actions** (`.gitea/workflows/build-apk.yaml`):
|
Die App verfügt über eine vollautomatische Build-Pipeline für **Gitea Actions** (`.gitea/workflows/build-apk.yaml`):
|
||||||
|
|
||||||
- **Build-Container:** `ghcr.io/cirruslabs/flutter:3.19.3` mit vorkonfiguriertem Android SDK und Java 17.
|
### Funktionen der Pipeline:
|
||||||
- **Automatisierte Qualitätskontrolle:** Führt vor jedem Build `flutter analyze` und `flutter test` aus.
|
- **Automatische Trigger:** Wird bei jedem `push` auf `main`, `master`, `refactor/**`, bei Git-Tags (`v*`) oder manuell im Webinterface (`workflow_dispatch`) ausgelöst.
|
||||||
- **Erzeugte APK-Pakete:**
|
- **Isolierte Build-Umgebung:** Nutzt das offizielle `ghcr.io/cirruslabs/flutter:3.19.3` Docker-Image mit vorinstalliertem Android SDK, Java 17 und Flutter.
|
||||||
1. `oggauer-gemeindetrommler-universal-release.apk` (Universelle Version für alle Android-Smartphones).
|
- **Qualitätssicherung:** Führt automatisch `flutter analyze` und `flutter test` aus, bevor der Build startet.
|
||||||
2. `oggauer-gemeindetrommler-arm64-v8a.apk` (Optimiert für moderne 64-Bit Geräte).
|
- **Vollständige APK-Generierung:**
|
||||||
3. `oggauer-gemeindetrommler-armeabi-v7a.apk` (Für ältere 32-Bit Geräte).
|
- `oggauer-gemeindetrommler-universal-release.apk` (Universelle Release-APK für alle Android-Geräte)
|
||||||
4. `oggauer-gemeindetrommler-x86_64.apk` (Für Emulatoren).
|
- `oggauer-gemeindetrommler-arm64-v8a.apk` (Für moderne 64-Bit Smartphones)
|
||||||
- **Download:** Die gebauten APKs stehen nach jedem Durchlauf als ZIP-Artefakt (`oggauer-gemeindetrommler-apks`) im Gitea-Reiter **Aktionen** zum Download bereit.
|
- `oggauer-gemeindetrommler-armeabi-v7a.apk` (Für ältere 32-Bit Smartphones)
|
||||||
|
- `oggauer-gemeindetrommler-x86_64.apk` (Für Emulatoren & ChromeOS)
|
||||||
|
- **Artifact-Upload:** Speichert die fertigen APKs als herunterladbare ZIP-Datei (`oggauer-gemeindetrommler-apks`) direkt im Gitea Run-Dashboard.
|
||||||
|
|
||||||
|
### APKs in Gitea herunterladen:
|
||||||
|
1. Im Gitea-Repository auf den Reiter **Aktionen** (*Actions*) klicken.
|
||||||
|
2. Den gewünschten Pipeline-Durchlauf auswählen.
|
||||||
|
3. Im Abschnitt **Artefakte** (*Artifacts*) das Paket `oggauer-gemeindetrommler-apks` herunterladen.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🛠️ Einrichtung & Lokale Ausführung
|
## 🛠️ Einrichtung & Lokaler Start
|
||||||
|
|
||||||
### Voraussetzungen:
|
### Voraussetzungen
|
||||||
- **Flutter SDK:** `>= 3.19.x`
|
1. **Flutter SDK** (empfohlen: `>= 3.19.x`)
|
||||||
- **Dart SDK:** Im Flutter SDK enthalten
|
2. **Dart SDK** (enthalten in Flutter)
|
||||||
- **Android Studio / VS Code / Xcode** mit entsprechenden Emulatoren oder Testgeräten
|
3. **Android Studio** / **Xcode** (für Emulatoren oder physische Geräte)
|
||||||
|
4. Konfiguriertes Firebase-Projekt (`gemeinde-trommler`)
|
||||||
|
|
||||||
### Befehle:
|
### Installation & Ausführung
|
||||||
```bash
|
```bash
|
||||||
# 1. Abhängigkeiten laden
|
# 1. Abhängigkeiten installieren
|
||||||
flutter pub get
|
flutter pub get
|
||||||
|
|
||||||
# 2. Statische Code-Analyse ausführen
|
# 2. Statische Code-Analyse ausführen
|
||||||
flutter analyze
|
flutter analyze
|
||||||
|
|
||||||
# 3. Unit-Tests ausführen
|
# 3. Tests ausführen
|
||||||
flutter test
|
flutter test
|
||||||
|
|
||||||
# 4. App im Entwicklungsmodus starten
|
# 4. App lokal starten
|
||||||
flutter run
|
flutter run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
gradle-wrapper.jar
|
||||||
/.gradle
|
/.gradle
|
||||||
/captures/
|
/captures/
|
||||||
|
/gradlew
|
||||||
|
/gradlew.bat
|
||||||
/local.properties
|
/local.properties
|
||||||
GeneratedPluginRegistrant.java
|
GeneratedPluginRegistrant.java
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
plugins {
|
|
||||||
id "com.android.application"
|
|
||||||
id "kotlin-android"
|
|
||||||
id "dev.flutter.flutter-gradle-plugin"
|
|
||||||
id "com.google.gms.google-services"
|
|
||||||
}
|
|
||||||
|
|
||||||
def localProperties = new Properties()
|
def localProperties = new Properties()
|
||||||
def localPropertiesFile = rootProject.file('local.properties')
|
def localPropertiesFile = rootProject.file('local.properties')
|
||||||
if (localPropertiesFile.exists()) {
|
if (localPropertiesFile.exists()) {
|
||||||
@@ -13,6 +6,11 @@ if (localPropertiesFile.exists()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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')
|
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||||||
if (flutterVersionCode == null) {
|
if (flutterVersionCode == null) {
|
||||||
flutterVersionCode = '1'
|
flutterVersionCode = '1'
|
||||||
@@ -23,6 +21,13 @@ if (flutterVersionName == null) {
|
|||||||
flutterVersionName = '1.0'
|
flutterVersionName = '1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.application'
|
||||||
|
// START: FlutterFire Configuration
|
||||||
|
apply plugin: 'com.google.gms.google-services'
|
||||||
|
// END: FlutterFire Configuration
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.oggauergemeindetrommler.app"
|
namespace "com.oggauergemeindetrommler.app"
|
||||||
compileSdkVersion flutter.compileSdkVersion
|
compileSdkVersion flutter.compileSdkVersion
|
||||||
@@ -70,4 +75,6 @@ flutter {
|
|||||||
source '../..'
|
source '../..'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {}
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,24 +35,5 @@
|
|||||||
</application>
|
</application>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<queries>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<data android:scheme="https" />
|
|
||||||
</intent>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<data android:scheme="http" />
|
|
||||||
</intent>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.SENDTO" />
|
|
||||||
<data android:scheme="mailto" />
|
|
||||||
</intent>
|
|
||||||
<intent>
|
|
||||||
<action android:name="android.intent.action.DIAL" />
|
|
||||||
<data android:scheme="tel" />
|
|
||||||
</intent>
|
|
||||||
</queries>
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -1,3 +1,18 @@
|
|||||||
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.9.22'
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:8.5.2'
|
||||||
|
// START: FlutterFire Configuration
|
||||||
|
classpath 'com.google.gms:google-services:4.4.1'
|
||||||
|
// END: FlutterFire Configuration
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
@@ -8,9 +23,7 @@ allprojects {
|
|||||||
|
|
||||||
rootProject.buildDir = '../build'
|
rootProject.buildDir = '../build'
|
||||||
subprojects {
|
subprojects {
|
||||||
project.buildDir = "${rootProject.buildDir}/${project.name}"
|
// Note: Do not override project.buildDir across different drives on Windows (H: vs C:)
|
||||||
}
|
|
||||||
subprojects {
|
|
||||||
|
|
||||||
// Inject namespace into plugins that don't have it (required for AGP 8+)
|
// Inject namespace into plugins that don't have it (required for AGP 8+)
|
||||||
afterEvaluate { project ->
|
afterEvaluate { project ->
|
||||||
@@ -30,4 +43,3 @@ subprojects {
|
|||||||
tasks.register("clean", Delete) {
|
tasks.register("clean", Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
org.gradle.jvmargs=-Xmx1536M -Djdk.lang.Process.launchMechanism=vfork
|
org.gradle.jvmargs=-Xmx1536M -Dandroid.prefs.root=C:/Users/nicol/.android
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
|
org.gradle.java.home=C:/Program Files/Zulu/zulu-20
|
||||||
|
|||||||
BIN
Binary file not shown.
Vendored
-160
@@ -1,160 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
##
|
|
||||||
## Gradle start up script for UN*X
|
|
||||||
##
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS=""
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=`basename "$0"`
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD="maximum"
|
|
||||||
|
|
||||||
warn ( ) {
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
die ( ) {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
case "`uname`" in
|
|
||||||
CYGWIN* )
|
|
||||||
cygwin=true
|
|
||||||
;;
|
|
||||||
Darwin* )
|
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
PRG="$0"
|
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
|
||||||
ls=`ls -ld "$PRG"`
|
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
|
||||||
PRG="$link"
|
|
||||||
else
|
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
||||||
else
|
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD="java"
|
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
|
||||||
if [ $? -eq 0 ] ; then
|
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
ulimit -n $MAX_FD
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
|
||||||
if $cygwin ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=$((i+1))
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
(0) set -- ;;
|
|
||||||
(1) set -- "$args0" ;;
|
|
||||||
(2) set -- "$args0" "$args1" ;;
|
|
||||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
|
||||||
function splitJvmOpts() {
|
|
||||||
JVM_OPTS=("$@")
|
|
||||||
}
|
|
||||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
|
||||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
|
||||||
|
|
||||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
|
||||||
Vendored
-90
@@ -1,90 +0,0 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS=
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:init
|
|
||||||
@rem Get command-line arguments, handling Windowz variants
|
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
|
||||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
|
||||||
|
|
||||||
:win9xME_args
|
|
||||||
@rem Slurp the command line arguments.
|
|
||||||
set CMD_LINE_ARGS=
|
|
||||||
set _SKIP=2
|
|
||||||
|
|
||||||
:win9xME_args_slurp
|
|
||||||
if "x%~1" == "x" goto execute
|
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
|
||||||
goto execute
|
|
||||||
|
|
||||||
:4NT_args
|
|
||||||
@rem Get arguments from the 4NT Shell from JP Software
|
|
||||||
set CMD_LINE_ARGS=%$
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
||||||
exit /b 1
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
||||||
+8
-27
@@ -1,30 +1,11 @@
|
|||||||
pluginManagement {
|
include ':app'
|
||||||
def flutterSdkPath = {
|
|
||||||
|
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
|
||||||
def properties = new Properties()
|
def properties = new Properties()
|
||||||
def localPropertiesFile = file("local.properties")
|
|
||||||
if (localPropertiesFile.exists()) {
|
|
||||||
localPropertiesFile.withInputStream { properties.load(it) }
|
|
||||||
}
|
|
||||||
def flutterSdkPath = properties.getProperty("flutter.sdk") ?: System.getenv('FLUTTER_ROOT') ?: System.getenv('FLUTTER_HOME')
|
|
||||||
assert flutterSdkPath != null, "flutter.sdk not set in local.properties or FLUTTER_ROOT environment variable"
|
|
||||||
return flutterSdkPath
|
|
||||||
}
|
|
||||||
settings.ext.flutterSdkPath = flutterSdkPath()
|
|
||||||
|
|
||||||
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
|
assert localPropertiesFile.exists()
|
||||||
|
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
|
||||||
|
|
||||||
repositories {
|
def flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||||
google()
|
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
|
||||||
mavenCentral()
|
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
|
||||||
id "com.android.application" version "8.5.2" apply false
|
|
||||||
id "org.jetbrains.kotlin.android" version "1.9.22" apply false
|
|
||||||
id "com.google.gms.google-services" version "4.4.1" apply false
|
|
||||||
}
|
|
||||||
|
|
||||||
include ":app"
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
@echo off
|
|
||||||
echo ========================================================
|
|
||||||
echo Oggauer Gemeindetrommler - Firestore Backup Tool
|
|
||||||
echo ========================================================
|
|
||||||
echo.
|
|
||||||
node scripts\backup_firestore.js
|
|
||||||
echo.
|
|
||||||
echo Backup abgeschlossen. Taste druecken zum Schliessen...
|
|
||||||
pause >nul
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
echo ========================================================
|
|
||||||
echo Oggauer Gemeindetrommler - Android APK Builder
|
|
||||||
echo ========================================================
|
|
||||||
echo.
|
|
||||||
|
|
||||||
set FLUTTER=C:\src\flutter\bin\flutter.bat
|
|
||||||
if not exist "%FLUTTER%" (
|
|
||||||
set FLUTTER=flutter
|
|
||||||
)
|
|
||||||
|
|
||||||
echo [1/4] Dependencies laden...
|
|
||||||
call %FLUTTER% pub get
|
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
|
||||||
echo [FEHLER] 'flutter pub get' fehlgeschlagen.
|
|
||||||
pause
|
|
||||||
exit /b %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo [2/4] Universelle Release APK bauen...
|
|
||||||
call %FLUTTER% build apk --release
|
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
|
||||||
echo [FEHLER] 'flutter build apk --release' fehlgeschlagen.
|
|
||||||
pause
|
|
||||||
exit /b %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo [3/4] Split-per-ABI APKs bauen (fuer schlankere Downloads)...
|
|
||||||
call %FLUTTER% build apk --release --split-per-abi
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo [4/4] APKs organisieren...
|
|
||||||
if not exist "release-apks" mkdir "release-apks"
|
|
||||||
|
|
||||||
if exist "build\app\outputs\flutter-apk\app-release.apk" (
|
|
||||||
copy /Y "build\app\outputs\flutter-apk\app-release.apk" "release-apks\oggauer-gemeindetrommler-universal.apk" >nul
|
|
||||||
)
|
|
||||||
if exist "build\app\outputs\flutter-apk\app-arm64-v8a-release.apk" (
|
|
||||||
copy /Y "build\app\outputs\flutter-apk\app-arm64-v8a-release.apk" "release-apks\oggauer-gemeindetrommler-arm64.apk" >nul
|
|
||||||
)
|
|
||||||
if exist "build\app\outputs\flutter-apk\app-armeabi-v7a-release.apk" (
|
|
||||||
copy /Y "build\app\outputs\flutter-apk\app-armeabi-v7a-release.apk" "release-apks\oggauer-gemeindetrommler-armv7.apk" >nul
|
|
||||||
)
|
|
||||||
if exist "build\app\outputs\flutter-apk\app-x86_64-release.apk" (
|
|
||||||
copy /Y "build\app\outputs\flutter-apk\app-x86_64-release.apk" "release-apks\oggauer-gemeindetrommler-x86_64.apk" >nul
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ========================================================
|
|
||||||
echo ERFOLG! Alle APKs befinden sich im Ordner:
|
|
||||||
echo %CD%\release-apks\
|
|
||||||
echo ========================================================
|
|
||||||
echo.
|
|
||||||
explorer release-apks
|
|
||||||
pause
|
|
||||||
+21
-47
@@ -2,60 +2,34 @@ rules_version = '2';
|
|||||||
service cloud.firestore {
|
service cloud.firestore {
|
||||||
match /databases/{database}/documents {
|
match /databases/{database}/documents {
|
||||||
|
|
||||||
// Hilfsfunktionen
|
// News / Neuigkeiten: Öffentlich lesbar, Schreiben für angemeldete Nutzer
|
||||||
function isAuthenticated() {
|
match /News/{document=**} {
|
||||||
return request.auth != null;
|
allow read: if true;
|
||||||
|
allow write: if request.auth != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAdmin() {
|
// Mängel & Anliegen: Öffentlich lesbar, Erstellen angemeldet, Löschen nur eigener Autor
|
||||||
return request.auth != null && (
|
match /Issues/{document} {
|
||||||
request.auth.token.admin == true ||
|
allow read: if true;
|
||||||
exists(/databases/$(database)/documents/Admins/$(request.auth.uid)) ||
|
allow create: if request.auth != null;
|
||||||
(request.auth.token.email != null && exists(/databases/$(database)/documents/Admins/$(request.auth.token.email)))
|
allow update: if request.auth != null;
|
||||||
);
|
allow delete: if request.auth != null &&
|
||||||
|
(resource.data.author_uid == request.auth.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAuthorOrAdmin() {
|
// Bürgerforum / Ideen: Öffentlich lesbar, Erstellen angemeldet, Löschen eigener Autor
|
||||||
return isAuthenticated() && (
|
match /CitizensForum/{document} {
|
||||||
(resource.data.author_uid != null && resource.data.author_uid == request.auth.uid) ||
|
allow read: if true;
|
||||||
(resource.data.authorUid != null && resource.data.authorUid == request.auth.uid) ||
|
allow create: if request.auth != null;
|
||||||
isAdmin()
|
allow update: if request.auth != null;
|
||||||
);
|
allow delete: if request.auth != null &&
|
||||||
|
(resource.data.author_uid == request.auth.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Benutzerprofile: Nutzer verwaltet eigenes Profil, Admins haben Vollzugriff
|
// Kontakt-Nachrichten: Jeder kann einsenden, Lesen nur berechtigte Nutzer
|
||||||
match /Users/{userId} {
|
|
||||||
allow read: if isAuthenticated() && (request.auth.uid == userId || isAdmin());
|
|
||||||
allow create, update: if isAuthenticated() && (request.auth.uid == userId || isAdmin());
|
|
||||||
allow delete: if isAdmin();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Admins-Sammlung: Angemeldete Nutzer können prüfen, nur Admins schreiben
|
|
||||||
match /Admins/{adminDoc} {
|
|
||||||
allow read: if isAuthenticated();
|
|
||||||
allow write: if isAdmin();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Öffentliche Sammlungen: News, Mängel (Issues) & Ideen (CitizensForum)
|
|
||||||
match /{collection}/{document=**} {
|
|
||||||
// Jeder darf News, Mängel & Ideen öffentlich lesen
|
|
||||||
allow read: if collection in ['News', 'Issues', 'CitizensForum'];
|
|
||||||
|
|
||||||
// Erstellen: News nur Admin; Mängel und Ideen für angemeldete Nutzer
|
|
||||||
allow create: if collection == 'News'
|
|
||||||
? isAdmin()
|
|
||||||
: (isAuthenticated() && collection in ['Issues', 'CitizensForum']);
|
|
||||||
|
|
||||||
// Ändern/Löschen nur der eigene Autor oder Admin
|
|
||||||
allow update, delete: if isAuthorOrAdmin() && collection in ['News', 'Issues', 'CitizensForum'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kontakt-Nachrichten: Geschützt (nur registrierte Nutzer senden, Lesen nur Admin & Autor)
|
|
||||||
match /ContactMessages/{document} {
|
match /ContactMessages/{document} {
|
||||||
// Senden nur für registrierte Nutzer (nicht-anonym)
|
allow create: if true;
|
||||||
allow create: if isAuthenticated() && request.auth.token.firebase.sign_in_provider != 'anonymous';
|
allow read, update, delete: if request.auth != null;
|
||||||
// Lesen, Ändern und Löschen für Admin und Autor
|
|
||||||
allow read, update, delete: if isAuthorOrAdmin();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# Gitea URL
|
|
||||||
GITEA_INSTANCE_URL=https://git.djnizz.at
|
|
||||||
|
|
||||||
# Hier das Token einfügen aus Gitea:
|
|
||||||
# Website-Verwaltung -> Aktionen -> Runner -> "Neuen Runner erstellen"
|
|
||||||
GITEA_RUNNER_REGISTRATION_TOKEN=hier_dein_token_einfuegen
|
|
||||||
|
|
||||||
# Beliebiger Name für den Runner
|
|
||||||
GITEA_RUNNER_NAME=oracle-arm-runner
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
# Gitea Act Runner (Oracle Cloud ARM64 / Docker)
|
|
||||||
|
|
||||||
Docker Compose Setup für den Gitea CI/CD Runner zum automatischen Bauen der Android-APKs.
|
|
||||||
|
|
||||||
## Schnellstart
|
|
||||||
|
|
||||||
1. **Token holen:**
|
|
||||||
In Gitea unter **Website-Verwaltung** (oder Repo-Einstellungen) ➔ **Aktionen** ➔ **Runner** ➔ **Neuen Runner erstellen** das Registrierungs-Token kopieren.
|
|
||||||
|
|
||||||
2. **Konfiguration erstellen:**
|
|
||||||
```bash
|
|
||||||
cp .env.example .env
|
|
||||||
nano .env
|
|
||||||
```
|
|
||||||
Dort das kopierte Token bei `GITEA_RUNNER_REGISTRATION_TOKEN` eintragen.
|
|
||||||
|
|
||||||
3. **Runner starten:**
|
|
||||||
```bash
|
|
||||||
docker compose up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **Logs ansehen:**
|
|
||||||
```bash
|
|
||||||
docker compose logs -f
|
|
||||||
```
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
gitea-runner:
|
|
||||||
image: gitea/act_runner:latest
|
|
||||||
container_name: gitea-runner
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
# URL deiner Gitea-Instanz
|
|
||||||
- GITEA_INSTANCE_URL=${GITEA_INSTANCE_URL:-https://git.djnizz.at}
|
|
||||||
# Registrierungs-Token aus Gitea (Website-Verwaltung -> Aktionen -> Runner -> "Neuen Runner erstellen")
|
|
||||||
- GITEA_RUNNER_REGISTRATION_TOKEN=${GITEA_RUNNER_REGISTRATION_TOKEN}
|
|
||||||
# Name des Runners in Gitea
|
|
||||||
- GITEA_RUNNER_NAME=${GITEA_RUNNER_NAME:-oracle-arm-runner}
|
|
||||||
# TLS-Verifizierung überspringen (falls SSL abgelaufen/selbstsigniert ist)
|
|
||||||
- GITEA_RUNNER_INSECURE=true
|
|
||||||
# Maximale parallele Jobs
|
|
||||||
- GITEA_RUNNER_CAPACITY=2
|
|
||||||
volumes:
|
|
||||||
# Docker-Socket des Host-Systems (nötig für Container-Builds wie Flutter)
|
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
# Persistenter Speicher: Registrierung bleibt nach Neustart erhalten
|
|
||||||
- ./data:/data
|
|
||||||
@@ -11,9 +11,6 @@ class PostItem {
|
|||||||
final String? street;
|
final String? street;
|
||||||
final String? category;
|
final String? category;
|
||||||
final String? status;
|
final String? status;
|
||||||
final String? pdfUrl;
|
|
||||||
final String? webUrl;
|
|
||||||
final bool isAussendung;
|
|
||||||
|
|
||||||
PostItem({
|
PostItem({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -26,9 +23,6 @@ class PostItem {
|
|||||||
this.street,
|
this.street,
|
||||||
this.category,
|
this.category,
|
||||||
this.status = 'Gemeldet',
|
this.status = 'Gemeldet',
|
||||||
this.pdfUrl,
|
|
||||||
this.webUrl,
|
|
||||||
this.isAussendung = false,
|
|
||||||
}) : imageUrls = imageUrls ?? (imageUrl.isNotEmpty ? [imageUrl] : []);
|
}) : imageUrls = imageUrls ?? (imageUrl.isNotEmpty ? [imageUrl] : []);
|
||||||
|
|
||||||
factory PostItem.fromFirestore(DocumentSnapshot doc) {
|
factory PostItem.fromFirestore(DocumentSnapshot doc) {
|
||||||
@@ -60,9 +54,6 @@ class PostItem {
|
|||||||
street: data['street'] as String?,
|
street: data['street'] as String?,
|
||||||
category: data['category'] as String?,
|
category: data['category'] as String?,
|
||||||
status: data['status'] as String? ?? 'Gemeldet',
|
status: data['status'] as String? ?? 'Gemeldet',
|
||||||
pdfUrl: data['pdfUrl'] as String?,
|
|
||||||
webUrl: data['webUrl'] as String?,
|
|
||||||
isAussendung: data['isAussendung'] as bool? ?? false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,163 +68,6 @@ class PostItem {
|
|||||||
if (street != null) 'street': street,
|
if (street != null) 'street': street,
|
||||||
if (category != null) 'category': category,
|
if (category != null) 'category': category,
|
||||||
if (status != null) 'status': status,
|
if (status != null) 'status': status,
|
||||||
if (pdfUrl != null) 'pdfUrl': pdfUrl,
|
|
||||||
if (webUrl != null) 'webUrl': webUrl,
|
|
||||||
if (isAussendung) 'isAussendung': isAussendung,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert to standard JSON map for local caching
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'title': title,
|
|
||||||
'description': description,
|
|
||||||
'imageUrl': imageUrl,
|
|
||||||
'imageUrls': imageUrls,
|
|
||||||
'createdDate': createdDate.toIso8601String(),
|
|
||||||
'authorUid': authorUid,
|
|
||||||
'street': street,
|
|
||||||
'category': category,
|
|
||||||
'status': status,
|
|
||||||
'pdfUrl': pdfUrl,
|
|
||||||
'webUrl': webUrl,
|
|
||||||
'isAussendung': isAussendung,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create from standard JSON map (local cache)
|
|
||||||
factory PostItem.fromJson(Map<String, dynamic> map) {
|
|
||||||
DateTime date;
|
|
||||||
if (map['createdDate'] is String) {
|
|
||||||
date = DateTime.tryParse(map['createdDate'] as String) ?? DateTime.now();
|
|
||||||
} else {
|
|
||||||
date = DateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
final String legacyImage = map['imageUrl'] as String? ?? '';
|
|
||||||
List<String> images = [];
|
|
||||||
if (map['imageUrls'] is List) {
|
|
||||||
images = List<String>.from(map['imageUrls'] as List);
|
|
||||||
} else if (legacyImage.isNotEmpty) {
|
|
||||||
images = [legacyImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
return PostItem(
|
|
||||||
id: map['id'] as String? ?? '',
|
|
||||||
title: map['title'] as String? ?? '',
|
|
||||||
description: map['description'] as String? ?? '',
|
|
||||||
imageUrl: legacyImage.isNotEmpty ? legacyImage : (images.isNotEmpty ? images.first : ''),
|
|
||||||
imageUrls: images,
|
|
||||||
createdDate: date,
|
|
||||||
authorUid: map['authorUid'] as String?,
|
|
||||||
street: map['street'] as String?,
|
|
||||||
category: map['category'] as String?,
|
|
||||||
status: map['status'] as String? ?? 'Gemeldet',
|
|
||||||
pdfUrl: map['pdfUrl'] as String?,
|
|
||||||
webUrl: map['webUrl'] as String?,
|
|
||||||
isAussendung: map['isAussendung'] as bool? ?? false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decode HTML entities commonly present in WordPress feeds
|
|
||||||
static String unescapeHtml(String text) {
|
|
||||||
var result = text
|
|
||||||
.replaceAll('&', '&')
|
|
||||||
.replaceAll('"', '"')
|
|
||||||
.replaceAll(''', "'")
|
|
||||||
.replaceAll(''', "'")
|
|
||||||
.replaceAll('<', '<')
|
|
||||||
.replaceAll('>', '>')
|
|
||||||
.replaceAll(' ', ' ')
|
|
||||||
.replaceAll('–', '–')
|
|
||||||
.replaceAll('—', '—')
|
|
||||||
.replaceAll('‘', '‘')
|
|
||||||
.replaceAll('’', '’')
|
|
||||||
.replaceAll('“', '“')
|
|
||||||
.replaceAll('”', '”')
|
|
||||||
.replaceAll('…', '…');
|
|
||||||
|
|
||||||
// Decode numerical entities &#DDD;
|
|
||||||
result = result.replaceAllMapped(RegExp(r'&#(\d+);'), (match) {
|
|
||||||
final code = int.tryParse(match.group(1)!);
|
|
||||||
return code != null ? String.fromCharCode(code) : match.group(0)!;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Decode hex numerical entities &#xHH;
|
|
||||||
result = result.replaceAllMapped(RegExp(r'&#x([0-9a-fA-F]+);'), (match) {
|
|
||||||
final code = int.tryParse(match.group(1)!, radix: 16);
|
|
||||||
return code != null ? String.fromCharCode(code) : match.group(0)!;
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extracts the direct PDF URL from WordPress post HTML content
|
|
||||||
static String? extractPdfUrl(String htmlContent) {
|
|
||||||
final pdfRegExp = RegExp(
|
|
||||||
r'https?://[^\s"<>]+?\.pdf',
|
|
||||||
caseSensitive: false,
|
|
||||||
);
|
|
||||||
final match = pdfRegExp.firstMatch(htmlContent);
|
|
||||||
if (match != null) {
|
|
||||||
return match.group(0);
|
|
||||||
}
|
|
||||||
// Fallback: check docx or doc files
|
|
||||||
final docRegExp = RegExp(
|
|
||||||
r'https?://[^\s"<>]+?\.(?:docx|doc)',
|
|
||||||
caseSensitive: false,
|
|
||||||
);
|
|
||||||
final docMatch = docRegExp.firstMatch(htmlContent);
|
|
||||||
return docMatch?.group(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Strip HTML tags and clean whitespace for preview text
|
|
||||||
static String extractCleanText(String htmlContent) {
|
|
||||||
var clean = htmlContent.replaceAll(RegExp(r'<style[^>]*>.*?</style>', dotAll: true), '');
|
|
||||||
clean = clean.replaceAll(RegExp(r'<script[^>]*>.*?</script>', dotAll: true), '');
|
|
||||||
clean = clean.replaceAll(RegExp(r'<[^>]*>'), ' ');
|
|
||||||
clean = unescapeHtml(clean);
|
|
||||||
clean = clean.replaceAll(RegExp(r'\s+'), ' ').trim();
|
|
||||||
return clean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a post from the WordPress REST API (/wp-json/wp/v2/posts)
|
|
||||||
factory PostItem.fromWordPressJson(Map<String, dynamic> json) {
|
|
||||||
final rawTitle = (json['title'] is Map)
|
|
||||||
? (json['title']['rendered'] as String? ?? '')
|
|
||||||
: (json['title'] as String? ?? '');
|
|
||||||
final title = unescapeHtml(rawTitle);
|
|
||||||
|
|
||||||
final rawContent = (json['content'] is Map)
|
|
||||||
? (json['content']['rendered'] as String? ?? '')
|
|
||||||
: (json['content'] as String? ?? '');
|
|
||||||
|
|
||||||
final pdfUrl = extractPdfUrl(rawContent);
|
|
||||||
final webUrl = json['link'] as String?;
|
|
||||||
|
|
||||||
DateTime date;
|
|
||||||
if (json['date'] is String) {
|
|
||||||
date = DateTime.tryParse(json['date'] as String) ?? DateTime.now();
|
|
||||||
} else {
|
|
||||||
date = DateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
String desc = extractCleanText(rawContent);
|
|
||||||
if (desc.isEmpty || desc == title) {
|
|
||||||
desc = 'Offizielle Aussendung des Bürgerforums Oggau (PDF).';
|
|
||||||
}
|
|
||||||
|
|
||||||
return PostItem(
|
|
||||||
id: 'wp_${json['id']}',
|
|
||||||
title: title.isNotEmpty ? title : 'Aussendung',
|
|
||||||
description: desc,
|
|
||||||
createdDate: date,
|
|
||||||
category: 'Aussendung',
|
|
||||||
status: 'Aussendung',
|
|
||||||
pdfUrl: pdfUrl,
|
|
||||||
webUrl: webUrl,
|
|
||||||
isAussendung: true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,604 +0,0 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
|
||||||
import '../services/firestore_service.dart';
|
|
||||||
|
|
||||||
class AdminMessagesScreen extends StatefulWidget {
|
|
||||||
const AdminMessagesScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AdminMessagesScreen> createState() => _AdminMessagesScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AdminMessagesScreenState extends State<AdminMessagesScreen> {
|
|
||||||
final FirestoreService _firestoreService = FirestoreService();
|
|
||||||
String _selectedFilter = 'all'; // 'all', 'Neu', 'In Bearbeitung', 'Erledigt'
|
|
||||||
String _searchQuery = '';
|
|
||||||
bool _isSearchActive = false;
|
|
||||||
final TextEditingController _searchController = TextEditingController();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_searchController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _sendMail(String email) async {
|
|
||||||
final uri = Uri(scheme: 'mailto', path: email);
|
|
||||||
try {
|
|
||||||
if (await canLaunchUrl(uri)) {
|
|
||||||
await launchUrl(uri);
|
|
||||||
} else {
|
|
||||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text('E-Mail-App konnte nicht geöffnet werden: $e')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _callPhone(String phone) async {
|
|
||||||
final cleanPhone = phone.replaceAll(RegExp(r'\s+'), '');
|
|
||||||
final uri = Uri(scheme: 'tel', path: cleanPhone);
|
|
||||||
try {
|
|
||||||
if (await canLaunchUrl(uri)) {
|
|
||||||
await launchUrl(uri);
|
|
||||||
} else {
|
|
||||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text('Telefon-App konnte nicht geöffnet werden: $e')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showMessageDetail(
|
|
||||||
BuildContext context,
|
|
||||||
String docId,
|
|
||||||
Map<String, dynamic> data,
|
|
||||||
) {
|
|
||||||
final firstName = data['firstName'] as String? ?? '';
|
|
||||||
final lastName = data['lastName'] as String? ?? '';
|
|
||||||
final rawName = '$firstName $lastName'.trim();
|
|
||||||
final fullName = rawName.isNotEmpty ? rawName : 'Unbekannter Absender';
|
|
||||||
final email = data['email'] as String? ?? '';
|
|
||||||
final phone = data['phone'] as String? ?? '';
|
|
||||||
final message = data['message'] as String? ?? '';
|
|
||||||
final currentStatus = data['status'] as String? ?? 'Neu';
|
|
||||||
|
|
||||||
DateTime createdDate;
|
|
||||||
if (data['createdDate'] is Timestamp) {
|
|
||||||
createdDate = (data['createdDate'] as Timestamp).toDate();
|
|
||||||
} else {
|
|
||||||
createdDate = DateTime.now();
|
|
||||||
}
|
|
||||||
final formattedDate =
|
|
||||||
DateFormat('dd.MM.yyyy HH:mm').format(createdDate);
|
|
||||||
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
||||||
),
|
|
||||||
builder: (ctx) => StatefulBuilder(
|
|
||||||
builder: (ctx, setModalState) => Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 20,
|
|
||||||
right: 20,
|
|
||||||
top: 20,
|
|
||||||
bottom: MediaQuery.of(ctx).viewInsets.bottom + 20,
|
|
||||||
),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Center(
|
|
||||||
child: Container(
|
|
||||||
width: 40,
|
|
||||||
height: 4,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade300,
|
|
||||||
borderRadius: BorderRadius.circular(2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
fullName,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 19,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
_buildStatusBadge(currentStatus),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
'Eingegangen: $formattedDate Uhr',
|
|
||||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
|
|
||||||
),
|
|
||||||
const Divider(height: 24),
|
|
||||||
if (email.isNotEmpty) ...[
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.email_outlined,
|
|
||||||
size: 18, color: Colors.blue),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
email,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: () => _sendMail(email),
|
|
||||||
icon: const Icon(Icons.send, size: 16),
|
|
||||||
label: const Text('Antworten'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (phone.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.phone_outlined,
|
|
||||||
size: 18, color: Colors.green),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
phone,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: () => _callPhone(phone),
|
|
||||||
icon: const Icon(Icons.call, size: 16),
|
|
||||||
label: const Text('Anrufen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
const Text(
|
|
||||||
'Nachricht / Anliegen:',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade100,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
|
||||||
),
|
|
||||||
child: SelectableText(
|
|
||||||
message,
|
|
||||||
style: const TextStyle(fontSize: 14, height: 1.45),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
const Text(
|
|
||||||
'Status ändern:',
|
|
||||||
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
_buildStatusButton(docId, 'Neu', currentStatus, Colors.orange),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
_buildStatusButton(
|
|
||||||
docId, 'In Bearbeitung', currentStatus, Colors.blue),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
_buildStatusButton(
|
|
||||||
docId, 'Erledigt', currentStatus, Colors.green),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
TextButton.icon(
|
|
||||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
|
||||||
icon: const Icon(Icons.delete_outline),
|
|
||||||
label: const Text('Nachricht löschen'),
|
|
||||||
onPressed: () async {
|
|
||||||
final confirm = await showDialog<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (dCtx) => AlertDialog(
|
|
||||||
title: const Text('Nachricht löschen?'),
|
|
||||||
content: const Text(
|
|
||||||
'Möchten Sie diese Bürgernachricht unwiderruflich löschen?'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(dCtx, false),
|
|
||||||
child: const Text('Abbrechen'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.red),
|
|
||||||
onPressed: () => Navigator.pop(dCtx, true),
|
|
||||||
child: const Text('Löschen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (confirm == true) {
|
|
||||||
await _firestoreService.deleteContactMessage(docId);
|
|
||||||
if (context.mounted) {
|
|
||||||
Navigator.pop(ctx);
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Nachricht gelöscht.')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx),
|
|
||||||
child: const Text('Schließen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildStatusButton(
|
|
||||||
String docId,
|
|
||||||
String targetStatus,
|
|
||||||
String currentStatus,
|
|
||||||
Color color,
|
|
||||||
) {
|
|
||||||
final isCurrent = currentStatus == targetStatus;
|
|
||||||
return Expanded(
|
|
||||||
child: OutlinedButton(
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
backgroundColor: isCurrent ? color.withOpacity(0.15) : null,
|
|
||||||
side: BorderSide(
|
|
||||||
color: isCurrent ? color : Colors.grey.shade300,
|
|
||||||
width: isCurrent ? 2 : 1,
|
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
),
|
|
||||||
onPressed: () async {
|
|
||||||
await _firestoreService.updateContactMessageStatus(
|
|
||||||
docId, targetStatus);
|
|
||||||
if (mounted) Navigator.pop(context);
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
targetStatus,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: isCurrent ? FontWeight.bold : FontWeight.normal,
|
|
||||||
color: isCurrent ? color : Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildStatusBadge(String status) {
|
|
||||||
Color bg;
|
|
||||||
Color fg;
|
|
||||||
switch (status) {
|
|
||||||
case 'In Bearbeitung':
|
|
||||||
bg = Colors.blue.shade50;
|
|
||||||
fg = Colors.blue.shade800;
|
|
||||||
break;
|
|
||||||
case 'Erledigt':
|
|
||||||
bg = Colors.green.shade50;
|
|
||||||
fg = Colors.green.shade800;
|
|
||||||
break;
|
|
||||||
case 'Neu':
|
|
||||||
default:
|
|
||||||
bg = Colors.orange.shade50;
|
|
||||||
fg = Colors.orange.shade900;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: bg,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(color: fg.withOpacity(0.3)),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
status,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: fg,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: _isSearchActive
|
|
||||||
? TextField(
|
|
||||||
controller: _searchController,
|
|
||||||
autofocus: true,
|
|
||||||
style: const TextStyle(color: Colors.black87),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Nachrichten durchsuchen...',
|
|
||||||
border: InputBorder.none,
|
|
||||||
hintStyle: TextStyle(color: Colors.grey.shade600),
|
|
||||||
),
|
|
||||||
onChanged: (val) => setState(() => _searchQuery = val.trim()),
|
|
||||||
)
|
|
||||||
: const Text('Posteingang (Bürgernachrichten)'),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(_isSearchActive ? Icons.close : Icons.search),
|
|
||||||
tooltip: _isSearchActive ? 'Suche beenden' : 'Suchen',
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
if (_isSearchActive) {
|
|
||||||
_isSearchActive = false;
|
|
||||||
_searchQuery = '';
|
|
||||||
_searchController.clear();
|
|
||||||
} else {
|
|
||||||
_isSearchActive = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
// Filter Chips
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
color: Colors.grey.shade50,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
ChoiceChip(
|
|
||||||
label: const Text('Alle'),
|
|
||||||
selected: _selectedFilter == 'all',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'all'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: const Icon(Icons.fiber_new,
|
|
||||||
size: 16, color: Colors.orange),
|
|
||||||
label: const Text('Neu'),
|
|
||||||
selected: _selectedFilter == 'Neu',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'Neu'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: const Icon(Icons.hourglass_top,
|
|
||||||
size: 16, color: Colors.blue),
|
|
||||||
label: const Text('In Bearbeitung'),
|
|
||||||
selected: _selectedFilter == 'In Bearbeitung',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'In Bearbeitung'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: const Icon(Icons.check_circle_outline,
|
|
||||||
size: 16, color: Colors.green),
|
|
||||||
label: const Text('Erledigt'),
|
|
||||||
selected: _selectedFilter == 'Erledigt',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'Erledigt'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
|
|
||||||
stream: _firestoreService.getContactMessagesStream(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Text(
|
|
||||||
'Fehler beim Abrufen der Nachrichten: ${snapshot.error}',
|
|
||||||
style: const TextStyle(color: Colors.red),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
|
|
||||||
final docs = snapshot.data?.docs ?? [];
|
|
||||||
final filteredDocs = docs.where((doc) {
|
|
||||||
final data = doc.data();
|
|
||||||
final status = data['status'] as String? ?? 'Neu';
|
|
||||||
if (_selectedFilter != 'all' && status != _selectedFilter) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_searchQuery.isNotEmpty) {
|
|
||||||
final q = _searchQuery.toLowerCase();
|
|
||||||
final fn = (data['firstName'] as String? ?? '').toLowerCase();
|
|
||||||
final ln = (data['lastName'] as String? ?? '').toLowerCase();
|
|
||||||
final em = (data['email'] as String? ?? '').toLowerCase();
|
|
||||||
final msg = (data['message'] as String? ?? '').toLowerCase();
|
|
||||||
return fn.contains(q) ||
|
|
||||||
ln.contains(q) ||
|
|
||||||
em.contains(q) ||
|
|
||||||
msg.contains(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
if (filteredDocs.isEmpty) {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.mark_email_read_outlined,
|
|
||||||
size: 64, color: Colors.grey.shade400),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
_searchQuery.isNotEmpty
|
|
||||||
? 'Keine Treffer für "'
|
|
||||||
: 'Keine Nachrichten vorhanden.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListView.separated(
|
|
||||||
itemCount: filteredDocs.length,
|
|
||||||
separatorBuilder: (ctx, i) => const Divider(height: 1),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final doc = filteredDocs[index];
|
|
||||||
final data = doc.data();
|
|
||||||
final firstName = data['firstName'] as String? ?? '';
|
|
||||||
final lastName = data['lastName'] as String? ?? '';
|
|
||||||
final rawName = '$firstName $lastName'.trim();
|
|
||||||
final fullName =
|
|
||||||
rawName.isNotEmpty ? rawName : 'Unbekannter Absender';
|
|
||||||
final email = data['email'] as String? ?? '';
|
|
||||||
final message = data['message'] as String? ?? '';
|
|
||||||
final status = data['status'] as String? ?? 'Neu';
|
|
||||||
|
|
||||||
DateTime createdDate;
|
|
||||||
if (data['createdDate'] is Timestamp) {
|
|
||||||
createdDate = (data['createdDate'] as Timestamp).toDate();
|
|
||||||
} else {
|
|
||||||
createdDate = DateTime.now();
|
|
||||||
}
|
|
||||||
final formattedDate =
|
|
||||||
DateFormat('dd.MM.yyyy HH:mm').format(createdDate);
|
|
||||||
|
|
||||||
return ListTile(
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16, vertical: 8),
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: status == 'Neu'
|
|
||||||
? Colors.orange.shade100
|
|
||||||
: status == 'In Bearbeitung'
|
|
||||||
? Colors.blue.shade100
|
|
||||||
: Colors.green.shade100,
|
|
||||||
child: Text(
|
|
||||||
fullName.isNotEmpty ? fullName[0].toUpperCase() : '?',
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: status == 'Neu'
|
|
||||||
? Colors.orange.shade900
|
|
||||||
: status == 'In Bearbeitung'
|
|
||||||
? Colors.blue.shade900
|
|
||||||
: Colors.green.shade900,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
title: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
fullName,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: status == 'Neu'
|
|
||||||
? FontWeight.bold
|
|
||||||
: FontWeight.w600,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
formattedDate,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
subtitle: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (email.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
email,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.blue.shade800,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
message,
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
color: Colors.grey.shade800,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
trailing: _buildStatusBadge(status),
|
|
||||||
onTap: () => _showMessageDetail(context, doc.id, data),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+68
-320
@@ -25,8 +25,7 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
final _loginPasswordController = TextEditingController();
|
final _loginPasswordController = TextEditingController();
|
||||||
|
|
||||||
// Register Controllers
|
// Register Controllers
|
||||||
final _regFirstNameController = TextEditingController();
|
final _regNameController = TextEditingController();
|
||||||
final _regLastNameController = TextEditingController();
|
|
||||||
final _regEmailController = TextEditingController();
|
final _regEmailController = TextEditingController();
|
||||||
final _regPasswordController = TextEditingController();
|
final _regPasswordController = TextEditingController();
|
||||||
final _regConfirmPasswordController = TextEditingController();
|
final _regConfirmPasswordController = TextEditingController();
|
||||||
@@ -37,14 +36,10 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
String? _errorMessage;
|
String? _errorMessage;
|
||||||
|
|
||||||
bool _obscureLoginPassword = true;
|
|
||||||
bool _obscureRegPassword = true;
|
|
||||||
bool _obscureRegConfirmPassword = true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_tabController = TabController(length: 2, vsync: this);
|
_tabController = TabController(length: 3, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -52,8 +47,7 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
_tabController.dispose();
|
_tabController.dispose();
|
||||||
_loginEmailController.dispose();
|
_loginEmailController.dispose();
|
||||||
_loginPasswordController.dispose();
|
_loginPasswordController.dispose();
|
||||||
_regFirstNameController.dispose();
|
_regNameController.dispose();
|
||||||
_regLastNameController.dispose();
|
|
||||||
_regEmailController.dispose();
|
_regEmailController.dispose();
|
||||||
_regPasswordController.dispose();
|
_regPasswordController.dispose();
|
||||||
_regConfirmPasswordController.dispose();
|
_regConfirmPasswordController.dispose();
|
||||||
@@ -95,14 +89,13 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleRegister() async {
|
Future<void> _handleRegister() async {
|
||||||
final firstName = _regFirstNameController.text.trim();
|
final name = _regNameController.text.trim();
|
||||||
final lastName = _regLastNameController.text.trim();
|
|
||||||
final email = _regEmailController.text.trim();
|
final email = _regEmailController.text.trim();
|
||||||
final password = _regPasswordController.text;
|
final password = _regPasswordController.text;
|
||||||
final confirm = _regConfirmPasswordController.text;
|
final confirm = _regConfirmPasswordController.text;
|
||||||
|
|
||||||
if (firstName.isEmpty || lastName.isEmpty || email.isEmpty || password.isEmpty) {
|
if (name.isEmpty || email.isEmpty || password.isEmpty) {
|
||||||
setState(() => _errorMessage = 'Bitte alle Pflichtfelder ausfüllen (Vorname, Nachname, E-Mail, Passwort).');
|
setState(() => _errorMessage = 'Bitte alle Pflichtfelder ausfüllen.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,46 +119,17 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
final error = await auth.signUpWithEmail(
|
final error = await auth.signUpWithEmail(
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
firstName: firstName,
|
name: name,
|
||||||
lastName: lastName,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _isLoading = false);
|
setState(() => _isLoading = false);
|
||||||
|
|
||||||
if (error == null) {
|
|
||||||
Navigator.pop(context);
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Konto erfolgreich erstellt! Wir haben einen Bestätigungslink an $email gesendet. Bitte prüfe dein Postfach.',
|
|
||||||
),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
duration: const Duration(seconds: 6),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
setState(() => _errorMessage = error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _handleGoogleSignIn() async {
|
|
||||||
setState(() {
|
|
||||||
_isLoading = true;
|
|
||||||
_errorMessage = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
final auth = Provider.of<AuthService>(context, listen: false);
|
|
||||||
final error = await auth.signInWithGoogle();
|
|
||||||
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() => _isLoading = false);
|
|
||||||
|
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text('Erfolgreich mit Google angemeldet!'),
|
content: Text('Konto erfolgreich erstellt! Willkommen im Bürgerforum.'),
|
||||||
backgroundColor: Colors.green,
|
backgroundColor: Colors.green,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -264,48 +228,22 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenHeight = MediaQuery.of(context).size.height;
|
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
insetPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: const BoxConstraints(maxWidth: 420),
|
||||||
maxWidth: 440,
|
|
||||||
maxHeight: screenHeight * 0.82,
|
|
||||||
),
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 16),
|
padding: const EdgeInsets.all(20.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
child: Image.asset(
|
|
||||||
'assets/images/logo.png',
|
|
||||||
height: 28,
|
|
||||||
errorBuilder: (_, __, ___) => const Icon(
|
|
||||||
Icons.campaign,
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
const Text(
|
const Text(
|
||||||
'Bürgerforum Oggau',
|
'Bürgerforum Oggau',
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
@@ -320,10 +258,11 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
tabs: const [
|
tabs: const [
|
||||||
Tab(text: 'Anmelden'),
|
Tab(text: 'Anmelden'),
|
||||||
Tab(text: 'Registrieren'),
|
Tab(text: 'Registrieren'),
|
||||||
|
Tab(text: 'Code-Login'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (_errorMessage != null) ...[
|
if (_errorMessage != null) ...[
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 12),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -347,15 +286,16 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 16),
|
||||||
Expanded(
|
Flexible(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 280,
|
||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
controller: _tabController,
|
controller: _tabController,
|
||||||
children: [
|
children: [
|
||||||
// Tab 1: Anmelden
|
// Tab 1: Login
|
||||||
SingleChildScrollView(
|
Column(
|
||||||
padding: const EdgeInsets.only(top: 6, bottom: 12),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
TextField(
|
TextField(
|
||||||
@@ -370,24 +310,11 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _loginPasswordController,
|
controller: _loginPasswordController,
|
||||||
obscureText: _obscureLoginPassword,
|
obscureText: true,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Passwort',
|
labelText: 'Passwort',
|
||||||
prefixIcon: const Icon(Icons.lock_outline),
|
prefixIcon: Icon(Icons.lock_outline),
|
||||||
suffixIcon: IconButton(
|
border: OutlineInputBorder(),
|
||||||
icon: Icon(
|
|
||||||
_obscureLoginPassword
|
|
||||||
? Icons.visibility_off
|
|
||||||
: Icons.visibility,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_obscureLoginPassword =
|
|
||||||
!_obscureLoginPassword;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Align(
|
Align(
|
||||||
@@ -400,11 +327,12 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const Spacer(),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: _isLoading ? null : _handleLogin,
|
onPressed: _isLoading ? null : _handleLogin,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 13),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 12),
|
||||||
),
|
),
|
||||||
child: _isLoading
|
child: _isLoading
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
@@ -413,77 +341,23 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2),
|
strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: const Text('Anmelden',
|
: const Text('Anmelden'),
|
||||||
style: TextStyle(fontSize: 15)),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
|
||||||
child: Text(
|
|
||||||
'ODER',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Colors.grey.shade500,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
_buildGoogleButton(label: 'Mit Google anmelden'),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Center(
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () => _tabController.animateTo(1),
|
|
||||||
child: const Text(
|
|
||||||
'Noch kein Konto? Hier registrieren oder Bürger-Code eingeben',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
|
|
||||||
// Tab 2: Registrierung & Bürger-Code
|
// Tab 2: Registrierung
|
||||||
SingleChildScrollView(
|
Column(
|
||||||
padding: const EdgeInsets.only(top: 6, bottom: 12),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
TextField(
|
||||||
children: [
|
controller: _regNameController,
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _regFirstNameController,
|
|
||||||
textCapitalization: TextCapitalization.words,
|
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Vorname *',
|
labelText: 'Name / Vorname',
|
||||||
prefixIcon: Icon(Icons.person_outline),
|
prefixIcon: Icon(Icons.person_outline),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _regLastNameController,
|
|
||||||
textCapitalization: TextCapitalization.words,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'Nachname *',
|
|
||||||
prefixIcon: Icon(Icons.person_outline),
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _regEmailController,
|
controller: _regEmailController,
|
||||||
@@ -492,60 +366,34 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
labelText: 'E-Mail-Adresse',
|
labelText: 'E-Mail-Adresse',
|
||||||
prefixIcon: Icon(Icons.email_outlined),
|
prefixIcon: Icon(Icons.email_outlined),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
helperText:
|
|
||||||
'Erhält einen Bestätigungslink zur Prüfung',
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _regPasswordController,
|
controller: _regPasswordController,
|
||||||
obscureText: _obscureRegPassword,
|
obscureText: true,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Passwort (mind. 6 Zeichen)',
|
labelText: 'Passwort (mind. 6 Zeichen)',
|
||||||
prefixIcon: const Icon(Icons.lock_outline),
|
prefixIcon: Icon(Icons.lock_outline),
|
||||||
suffixIcon: IconButton(
|
border: OutlineInputBorder(),
|
||||||
icon: Icon(
|
|
||||||
_obscureRegPassword
|
|
||||||
? Icons.visibility_off
|
|
||||||
: Icons.visibility,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_obscureRegPassword = !_obscureRegPassword;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _regConfirmPasswordController,
|
controller: _regConfirmPasswordController,
|
||||||
obscureText: _obscureRegConfirmPassword,
|
obscureText: true,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Passwort bestätigen',
|
labelText: 'Passwort bestätigen',
|
||||||
prefixIcon: const Icon(Icons.lock_outline),
|
prefixIcon: Icon(Icons.lock_outline),
|
||||||
suffixIcon: IconButton(
|
border: OutlineInputBorder(),
|
||||||
icon: Icon(
|
|
||||||
_obscureRegConfirmPassword
|
|
||||||
? Icons.visibility_off
|
|
||||||
: Icons.visibility,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_obscureRegConfirmPassword =
|
|
||||||
!_obscureRegConfirmPassword;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const Spacer(),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: _isLoading ? null : _handleRegister,
|
onPressed: _isLoading ? null : _handleRegister,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 13),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 12),
|
||||||
),
|
),
|
||||||
child: _isLoading
|
child: _isLoading
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
@@ -554,104 +402,52 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2),
|
strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: const Text(
|
: const Text('Konto erstellen'),
|
||||||
'Konto erstellen & E-Mail bestätigen',
|
|
||||||
style: TextStyle(fontSize: 14)),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
|
||||||
child: Text(
|
|
||||||
'ODER',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Colors.grey.shade500,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
|
||||||
_buildGoogleButton(label: 'Mit Google registrieren'),
|
// Tab 3: Bürger-Code
|
||||||
const SizedBox(height: 18),
|
Column(
|
||||||
Row(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
const Text(
|
||||||
Padding(
|
'Du möchtest kein persönliches Konto anlegen? Gib einfach den Zugangscode des Bürgerforums ein, um sofort Mängel und Ideen melden zu können.',
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
style:
|
||||||
child: Text(
|
TextStyle(fontSize: 13, color: Colors.black87),
|
||||||
'ODER MIT BÜRGER-CODE',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 16),
|
||||||
),
|
TextField(
|
||||||
Expanded(child: Divider(color: Colors.grey.shade300)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 14),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.blue.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(color: Colors.blue.shade100),
|
|
||||||
),
|
|
||||||
child: const Text(
|
|
||||||
'Kein persönliches Konto gewünscht? Gib den Zugangscode des Bürgerforums ein (z.B. oggau), um sofort Mängel & Ideen melden zu können.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12, color: Colors.black87),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
controller: _codeController,
|
controller: _codeController,
|
||||||
|
obscureText: true,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Bürger-Zugangscode',
|
labelText: 'Bürger-Zugangscode',
|
||||||
prefixIcon: Icon(Icons.key_outlined),
|
prefixIcon: Icon(Icons.key_outlined),
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
hintText: 'z.B. oggau',
|
hintText: 'z.B. oggau',
|
||||||
isDense: true,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const Spacer(),
|
||||||
const SizedBox(width: 8),
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: _isLoading ? null : _handleCodeUnlock,
|
onPressed: _isLoading ? null : _handleCodeUnlock,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding:
|
||||||
vertical: 14, horizontal: 16),
|
const EdgeInsets.symmetric(vertical: 12),
|
||||||
backgroundColor: Colors.blue.shade700,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
),
|
||||||
child: const Text('Freischalten'),
|
child: _isLoading
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text('Freischalten'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
|
||||||
Center(
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () => _tabController.animateTo(0),
|
|
||||||
child: const Text(
|
|
||||||
'Bereits ein Konto? Hier anmelden',
|
|
||||||
style: TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -660,52 +456,4 @@ class _AuthDialogState extends State<AuthDialog>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildGoogleButton({required String label}) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: _isLoading ? null : _handleGoogleSignIn,
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 11, horizontal: 16),
|
|
||||||
side: BorderSide(color: Colors.grey.shade300),
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
_buildGoogleIcon(),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildGoogleIcon() {
|
|
||||||
return Container(
|
|
||||||
width: 22,
|
|
||||||
height: 22,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
border: Border.all(color: Colors.grey.shade200),
|
|
||||||
),
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: const Text(
|
|
||||||
'G',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Color(0xFF4285F4),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-261
@@ -1,9 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import '../services/auth_service.dart';
|
|
||||||
import '../services/firestore_service.dart';
|
import '../services/firestore_service.dart';
|
||||||
import 'admin_messages_screen.dart';
|
|
||||||
import 'auth_dialog.dart';
|
|
||||||
|
|
||||||
class ContactScreen extends StatefulWidget {
|
class ContactScreen extends StatefulWidget {
|
||||||
const ContactScreen({super.key});
|
const ContactScreen({super.key});
|
||||||
@@ -33,12 +29,11 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _submitForm(AuthService auth) async {
|
bool _isValidEmail(String email) {
|
||||||
if (!auth.isRegisteredUser) {
|
return RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(email);
|
||||||
await AuthDialog.show(context);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _submitForm() async {
|
||||||
if (!_formKey.currentState!.validate() || _isSubmitting) return;
|
if (!_formKey.currentState!.validate() || _isSubmitting) return;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -46,27 +41,19 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final firstName = auth.firstName.isNotEmpty
|
|
||||||
? auth.firstName
|
|
||||||
: _firstNameController.text.trim();
|
|
||||||
final lastName = auth.lastName.isNotEmpty
|
|
||||||
? auth.lastName
|
|
||||||
: _lastNameController.text.trim();
|
|
||||||
final email = (auth.email != null && auth.email!.isNotEmpty)
|
|
||||||
? auth.email!
|
|
||||||
: _emailController.text.trim();
|
|
||||||
|
|
||||||
await _firestoreService.submitContactMessage(
|
await _firestoreService.submitContactMessage(
|
||||||
firstName: firstName,
|
firstName: _firstNameController.text.trim(),
|
||||||
lastName: lastName,
|
lastName: _lastNameController.text.trim(),
|
||||||
email: email,
|
email: _emailController.text.trim(),
|
||||||
phone: _phoneController.text.trim(),
|
phone: _phoneController.text.trim(),
|
||||||
message: _messageController.text.trim(),
|
message: _messageController.text.trim(),
|
||||||
authorUid: auth.user?.uid,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
|
_firstNameController.clear();
|
||||||
|
_lastNameController.clear();
|
||||||
|
_emailController.clear();
|
||||||
_phoneController.clear();
|
_phoneController.clear();
|
||||||
_messageController.clear();
|
_messageController.clear();
|
||||||
|
|
||||||
@@ -95,45 +82,10 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final auth = Provider.of<AuthService>(context);
|
|
||||||
final isRegistered = auth.isRegisteredUser;
|
|
||||||
|
|
||||||
// Sync controllers with authenticated user details
|
|
||||||
if (isRegistered) {
|
|
||||||
if (_firstNameController.text != auth.firstName) {
|
|
||||||
_firstNameController.text = auth.firstName;
|
|
||||||
}
|
|
||||||
if (_lastNameController.text != auth.lastName) {
|
|
||||||
_lastNameController.text = auth.lastName;
|
|
||||||
}
|
|
||||||
if (_emailController.text != (auth.email ?? '')) {
|
|
||||||
_emailController.text = auth.email ?? '';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (_firstNameController.text.isNotEmpty) _firstNameController.clear();
|
|
||||||
if (_lastNameController.text.isNotEmpty) _lastNameController.clear();
|
|
||||||
if (_emailController.text.isNotEmpty) _emailController.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Kontakt Bürgerforum'),
|
title: const Text('Kontakt Bürgerforum'),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
actions: [
|
|
||||||
if (auth.isAdmin)
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.inbox),
|
|
||||||
tooltip: 'Posteingang: Bürgernachrichten',
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const AdminMessagesScreen(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
||||||
@@ -142,123 +94,20 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
if (auth.isAdmin) ...[
|
|
||||||
Card(
|
|
||||||
color: Colors.indigo.shade50,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
side: BorderSide(color: Colors.indigo.shade200),
|
|
||||||
),
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: Colors.indigo.shade700,
|
|
||||||
child: const Icon(Icons.mark_email_unread, color: Colors.white),
|
|
||||||
),
|
|
||||||
title: const Text(
|
|
||||||
'Admin-Posteingang',
|
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
subtitle: const Text(
|
|
||||||
'Alle eingegangenen Bürgernachrichten einsehen & verwalten'),
|
|
||||||
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const AdminMessagesScreen(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
if (!isRegistered) ...[
|
|
||||||
Card(
|
|
||||||
color: Colors.amber.shade50,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
side: BorderSide(color: Colors.amber.shade300),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(14.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.lock_outline,
|
|
||||||
color: Colors.amber.shade900, size: 22),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'Anmeldung erforderlich',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.amber.shade900,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
Text(
|
|
||||||
'Um eine Nachricht an das Bürgerforum zu senden, ist ein registriertes Benutzerkonto erforderlich. Deine Kontaktdaten werden dann automatisch hinterlegt.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 13, color: Colors.grey.shade800),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
onPressed: () => AuthDialog.show(context),
|
|
||||||
icon: const Icon(Icons.login),
|
|
||||||
label: const Text('Jetzt anmelden oder registrieren'),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.blue.shade700,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 11),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
] else ...[
|
|
||||||
Card(
|
Card(
|
||||||
color: Colors.blue.shade50,
|
color: Colors.blue.shade50,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
side: BorderSide(color: Colors.blue.shade100),
|
child: const Padding(
|
||||||
),
|
padding: EdgeInsets.all(14.0),
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(12.0),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.verified_user_outlined,
|
Icon(Icons.mail_outline, color: Colors.blue, size: 28),
|
||||||
color: Colors.blue.shade700, size: 24),
|
SizedBox(width: 12),
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Text(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
'Hier kannst du direkt mit dem Bürgerforum Oggau in Kontakt treten. Wir freuen uns über deine Anregungen und Fragen!',
|
||||||
children: [
|
style: TextStyle(fontSize: 13),
|
||||||
Text(
|
|
||||||
'Angemeldet als ${auth.displayName ?? auth.email}',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
'Deine Kontaktdaten sind automatisch hinterlegt.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12, color: Colors.grey.shade700),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -266,62 +115,33 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
],
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _firstNameController,
|
controller: _firstNameController,
|
||||||
readOnly: true,
|
decoration: const InputDecoration(
|
||||||
style: TextStyle(
|
|
||||||
color: isRegistered
|
|
||||||
? Colors.black87
|
|
||||||
: Colors.grey.shade600,
|
|
||||||
fontWeight: isRegistered
|
|
||||||
? FontWeight.w500
|
|
||||||
: FontWeight.normal,
|
|
||||||
),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Vorname *',
|
labelText: 'Vorname *',
|
||||||
hintText:
|
border: OutlineInputBorder(),
|
||||||
isRegistered ? null : 'Wird automatisch ausgefüllt',
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey.shade100,
|
|
||||||
prefixIcon: const Icon(Icons.person_outline),
|
|
||||||
suffixIcon: isRegistered
|
|
||||||
? const Icon(Icons.lock_outline,
|
|
||||||
size: 18, color: Colors.grey)
|
|
||||||
: null,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
|
validator: (value) =>
|
||||||
|
(value == null || value.trim().isEmpty)
|
||||||
|
? 'Bitte Vorname eingeben'
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _lastNameController,
|
controller: _lastNameController,
|
||||||
readOnly: true,
|
decoration: const InputDecoration(
|
||||||
style: TextStyle(
|
|
||||||
color: isRegistered
|
|
||||||
? Colors.black87
|
|
||||||
: Colors.grey.shade600,
|
|
||||||
fontWeight: isRegistered
|
|
||||||
? FontWeight.w500
|
|
||||||
: FontWeight.normal,
|
|
||||||
),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Nachname *',
|
labelText: 'Nachname *',
|
||||||
hintText:
|
border: OutlineInputBorder(),
|
||||||
isRegistered ? null : 'Wird automatisch ausgefüllt',
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey.shade100,
|
|
||||||
prefixIcon: const Icon(Icons.person_outline),
|
|
||||||
suffixIcon: isRegistered
|
|
||||||
? const Icon(Icons.lock_outline,
|
|
||||||
size: 18, color: Colors.grey)
|
|
||||||
: null,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
|
validator: (value) =>
|
||||||
|
(value == null || value.trim().isEmpty)
|
||||||
|
? 'Bitte Nachname eingeben'
|
||||||
|
: null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -329,58 +149,41 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
readOnly: true,
|
keyboardType: TextInputType.emailAddress,
|
||||||
style: TextStyle(
|
decoration: const InputDecoration(
|
||||||
color: isRegistered ? Colors.black87 : Colors.grey.shade600,
|
|
||||||
fontWeight:
|
|
||||||
isRegistered ? FontWeight.w500 : FontWeight.normal,
|
|
||||||
),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'E-Mail-Adresse *',
|
labelText: 'E-Mail-Adresse *',
|
||||||
hintText:
|
border: OutlineInputBorder(),
|
||||||
isRegistered ? null : 'Wird durch Anmeldung ausgefüllt',
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey.shade100,
|
|
||||||
prefixIcon: const Icon(Icons.email_outlined),
|
|
||||||
suffixIcon: isRegistered
|
|
||||||
? const Icon(Icons.lock_outline,
|
|
||||||
size: 18, color: Colors.grey)
|
|
||||||
: null,
|
|
||||||
helperText: isRegistered
|
|
||||||
? 'Antworten des Bürgerforums gehen an diese E-Mail'
|
|
||||||
: null,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.trim().isEmpty) {
|
||||||
|
return 'Bitte E-Mail-Adresse eingeben';
|
||||||
|
}
|
||||||
|
if (!_isValidEmail(value.trim())) {
|
||||||
|
return 'Bitte eine gültige E-Mail eingeben';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _phoneController,
|
controller: _phoneController,
|
||||||
keyboardType: TextInputType.phone,
|
keyboardType: TextInputType.phone,
|
||||||
enabled: isRegistered,
|
decoration: const InputDecoration(
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Rückrufnummer (optional)',
|
labelText: 'Rückrufnummer (optional)',
|
||||||
prefixIcon: const Icon(Icons.phone_outlined),
|
border: OutlineInputBorder(),
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
helperText: isRegistered
|
|
||||||
? 'Optional für eventuelle telefonische Rückfragen'
|
|
||||||
: null,
|
|
||||||
filled: !isRegistered,
|
|
||||||
fillColor: !isRegistered ? Colors.grey.shade100 : null,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _messageController,
|
controller: _messageController,
|
||||||
maxLines: 5,
|
maxLines: 5,
|
||||||
enabled: isRegistered,
|
decoration: const InputDecoration(
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'Ihr Anliegen / Ihre Nachricht *',
|
labelText: 'Ihr Anliegen / Ihre Nachricht *',
|
||||||
alignLabelWithHint: true,
|
alignLabelWithHint: true,
|
||||||
border: const OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
filled: !isRegistered,
|
|
||||||
fillColor: !isRegistered ? Colors.grey.shade100 : null,
|
|
||||||
),
|
),
|
||||||
validator: (value) => (value == null || value.trim().isEmpty)
|
validator: (value) =>
|
||||||
|
(value == null || value.trim().isEmpty)
|
||||||
? 'Bitte Ihre Nachricht eingeben'
|
? 'Bitte Ihre Nachricht eingeben'
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
@@ -398,29 +201,16 @@ class _ContactScreenState extends State<ContactScreen> {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 48,
|
height: 48,
|
||||||
child: ElevatedButton.icon(
|
child: ElevatedButton.icon(
|
||||||
onPressed: !isRegistered
|
onPressed: _isSubmitting ? null : _submitForm,
|
||||||
? () => AuthDialog.show(context)
|
|
||||||
: (_isSubmitting ? null : () => _submitForm(auth)),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: isRegistered
|
|
||||||
? Colors.blue.shade800
|
|
||||||
: Colors.grey.shade700,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
),
|
|
||||||
icon: _isSubmitting
|
icon: _isSubmitting
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
width: 20,
|
width: 20,
|
||||||
height: 20,
|
height: 20,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
strokeWidth: 2, color: Colors.white),
|
|
||||||
)
|
)
|
||||||
: Icon(!isRegistered ? Icons.login : Icons.send),
|
: const Icon(Icons.send),
|
||||||
label: Text(
|
label: Text(
|
||||||
!isRegistered
|
_isSubmitting ? 'Wird gesendet...' : 'Nachricht absenden',
|
||||||
? 'Anmelden zum Absenden'
|
|
||||||
: (_isSubmitting
|
|
||||||
? 'Wird gesendet...'
|
|
||||||
: 'Nachricht absenden'),
|
|
||||||
style: const TextStyle(fontSize: 16),
|
style: const TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import '../models/post_item.dart';
|
import '../models/post_item.dart';
|
||||||
import '../services/pdf_service.dart';
|
import '../services/pdf_service.dart';
|
||||||
import 'pdf_viewer_screen.dart';
|
|
||||||
|
|
||||||
class DetailScreen extends StatelessWidget {
|
class DetailScreen extends StatelessWidget {
|
||||||
final PostItem item;
|
final PostItem item;
|
||||||
@@ -124,41 +123,6 @@ class DetailScreen extends StatelessWidget {
|
|||||||
item.description,
|
item.description,
|
||||||
style: const TextStyle(fontSize: 15, height: 1.5),
|
style: const TextStyle(fontSize: 15, height: 1.5),
|
||||||
),
|
),
|
||||||
if (item.pdfUrl != null && item.pdfUrl!.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Card(
|
|
||||||
color: Colors.red.shade50,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
side: BorderSide(color: Colors.red.shade200),
|
|
||||||
),
|
|
||||||
child: ListTile(
|
|
||||||
leading: const CircleAvatar(
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
child: Icon(Icons.picture_as_pdf, color: Colors.white),
|
|
||||||
),
|
|
||||||
title: const Text(
|
|
||||||
'PDF-Aussendung ansehen',
|
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
subtitle:
|
|
||||||
const Text('Dokument jetzt in der App öffnen und lesen'),
|
|
||||||
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
|
|
||||||
onTap: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (ctx) => PdfViewerScreen(
|
|
||||||
title: item.title,
|
|
||||||
pdfUrl: item.pdfUrl!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// Additional images gallery if there are multiple images
|
// Additional images gallery if there are multiple images
|
||||||
if (item.imageUrls.length > 1) ...[
|
if (item.imageUrls.length > 1) ...[
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../services/auth_service.dart';
|
import '../services/auth_service.dart';
|
||||||
import 'auth_dialog.dart';
|
import 'auth_dialog.dart';
|
||||||
import 'user_management_screen.dart';
|
|
||||||
|
|
||||||
class InfoScreen extends StatelessWidget {
|
class InfoScreen extends StatelessWidget {
|
||||||
const InfoScreen({super.key});
|
const InfoScreen({super.key});
|
||||||
@@ -52,9 +51,7 @@ class InfoScreen extends StatelessWidget {
|
|||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
// Bürgerforum Access & Account Card
|
// Bürgerforum Access & Account Card
|
||||||
Card(
|
Card(
|
||||||
color: auth.isAdmin
|
color: auth.isRegisteredUser
|
||||||
? Colors.indigo.shade50
|
|
||||||
: auth.isRegisteredUser
|
|
||||||
? Colors.green.shade50
|
? Colors.green.shade50
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Colors.teal.shade50
|
? Colors.teal.shade50
|
||||||
@@ -68,16 +65,12 @@ class InfoScreen extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
auth.isAdmin
|
auth.isRegisteredUser
|
||||||
? Icons.admin_panel_settings
|
|
||||||
: auth.isRegisteredUser
|
|
||||||
? Icons.account_circle
|
? Icons.account_circle
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Icons.verified_user
|
? Icons.verified_user
|
||||||
: Icons.lock_outline,
|
: Icons.lock_outline,
|
||||||
color: auth.isAdmin
|
color: auth.isRegisteredUser
|
||||||
? Colors.indigo.shade700
|
|
||||||
: auth.isRegisteredUser
|
|
||||||
? Colors.green.shade700
|
? Colors.green.shade700
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Colors.teal.shade800
|
? Colors.teal.shade800
|
||||||
@@ -90,9 +83,7 @@ class InfoScreen extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
auth.isAdmin
|
auth.isRegisteredUser
|
||||||
? 'Administrator'
|
|
||||||
: auth.isRegisteredUser
|
|
||||||
? (auth.displayName?.isNotEmpty == true
|
? (auth.displayName?.isNotEmpty == true
|
||||||
? auth.displayName!
|
? auth.displayName!
|
||||||
: 'Bürger-Konto')
|
: 'Bürger-Konto')
|
||||||
@@ -104,9 +95,7 @@ class InfoScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
Text(
|
Text(
|
||||||
auth.isAdmin
|
auth.isRegisteredUser
|
||||||
? '${auth.email ?? "Angemeldet"} (Admin-Rechte aktiv)'
|
|
||||||
: auth.isRegisteredUser
|
|
||||||
? auth.email ?? 'Angemeldet'
|
? auth.email ?? 'Angemeldet'
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? 'Mängel & Ideen freigeschaltet'
|
? 'Mängel & Ideen freigeschaltet'
|
||||||
@@ -137,29 +126,6 @@ class InfoScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (auth.isAdmin) ...[
|
|
||||||
const Divider(height: 20),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
icon: const Icon(Icons.manage_accounts),
|
|
||||||
label: const Text('Benutzerverwaltung & Admin-Rechte'),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Colors.indigo.shade700,
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (_) => const UserManagementScreen(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (!auth.isRegisteredUser && auth.isCommunityUnlocked) ...[
|
if (!auth.isRegisteredUser && auth.isCommunityUnlocked) ...[
|
||||||
const Divider(height: 16),
|
const Divider(height: 16),
|
||||||
InkWell(
|
InkWell(
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
import 'dart:typed_data';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:pdf/pdf.dart';
|
|
||||||
import 'package:printing/printing.dart';
|
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
|
||||||
|
|
||||||
class PdfViewerScreen extends StatefulWidget {
|
|
||||||
final String title;
|
|
||||||
final String pdfUrl;
|
|
||||||
|
|
||||||
const PdfViewerScreen({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.pdfUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<PdfViewerScreen> createState() => _PdfViewerScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PdfViewerScreenState extends State<PdfViewerScreen> {
|
|
||||||
final TransformationController _transformationController =
|
|
||||||
TransformationController();
|
|
||||||
double _zoomLevel = 1.0;
|
|
||||||
Uint8List? _cachedBytes;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_transformationController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _zoomIn() {
|
|
||||||
setState(() {
|
|
||||||
_zoomLevel = (_zoomLevel * 1.3).clamp(0.8, 5.0);
|
|
||||||
_transformationController.value = Matrix4.identity()..scale(_zoomLevel);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _zoomOut() {
|
|
||||||
setState(() {
|
|
||||||
_zoomLevel = (_zoomLevel / 1.3).clamp(0.8, 5.0);
|
|
||||||
_transformationController.value = Matrix4.identity()..scale(_zoomLevel);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void _resetZoom() {
|
|
||||||
setState(() {
|
|
||||||
_zoomLevel = 1.0;
|
|
||||||
_transformationController.value = Matrix4.identity();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _openExternal() async {
|
|
||||||
final uri = Uri.parse(widget.pdfUrl);
|
|
||||||
try {
|
|
||||||
final launched = await launchUrl(
|
|
||||||
uri,
|
|
||||||
mode: LaunchMode.externalApplication,
|
|
||||||
);
|
|
||||||
if (!launched) {
|
|
||||||
await launchUrl(uri, mode: LaunchMode.platformDefault);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text('Browser konnte nicht geöffnet werden: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _sharePdf() async {
|
|
||||||
if (_cachedBytes != null) {
|
|
||||||
final safeTitle =
|
|
||||||
widget.title.replaceAll(RegExp(r'[\\/:*?<>|]'), '_');
|
|
||||||
await Printing.sharePdf(
|
|
||||||
bytes: _cachedBytes!,
|
|
||||||
filename: '$safeTitle.pdf',
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('PDF wird noch geladen...')),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final safeTitle =
|
|
||||||
widget.title.replaceAll(RegExp(r'[\\/:*?<>|]'), '_');
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text(widget.title, overflow: TextOverflow.ellipsis),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.share),
|
|
||||||
tooltip: 'PDF teilen / drucken',
|
|
||||||
onPressed: _sharePdf,
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.open_in_browser),
|
|
||||||
tooltip: 'Im Browser öffnen',
|
|
||||||
onPressed: _openExternal,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Stack(
|
|
||||||
children: [
|
|
||||||
PdfPreview.builder(
|
|
||||||
build: (PdfPageFormat format) async {
|
|
||||||
if (_cachedBytes != null) return _cachedBytes!;
|
|
||||||
final response = await http
|
|
||||||
.get(Uri.parse(widget.pdfUrl))
|
|
||||||
.timeout(const Duration(seconds: 15));
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
_cachedBytes = response.bodyBytes;
|
|
||||||
return response.bodyBytes;
|
|
||||||
}
|
|
||||||
throw Exception(
|
|
||||||
'Fehler beim Abrufen der Datei (${response.statusCode})');
|
|
||||||
},
|
|
||||||
canChangeOrientation: false,
|
|
||||||
canChangePageFormat: false,
|
|
||||||
canDebug: false,
|
|
||||||
allowPrinting: false,
|
|
||||||
allowSharing: false,
|
|
||||||
useActions: false,
|
|
||||||
pdfFileName: '$safeTitle.pdf',
|
|
||||||
loadingWidget: const Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
CircularProgressIndicator(),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text('Aussendung wird geladen...'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onError: (context, error) => Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.error_outline, color: Colors.red, size: 48),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
'Fehler beim Laden des Dokuments: $error',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(color: Colors.red),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
ElevatedButton.icon(
|
|
||||||
onPressed: _openExternal,
|
|
||||||
icon: const Icon(Icons.open_in_browser),
|
|
||||||
label: const Text('Direkt im Browser öffnen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
pagesBuilder: (context, pages) {
|
|
||||||
return InteractiveViewer(
|
|
||||||
transformationController: _transformationController,
|
|
||||||
minScale: 0.8,
|
|
||||||
maxScale: 5.0,
|
|
||||||
panEnabled: true,
|
|
||||||
scaleEnabled: true,
|
|
||||||
onInteractionEnd: (details) {
|
|
||||||
final scale =
|
|
||||||
_transformationController.value.getMaxScaleOnAxis();
|
|
||||||
if (scale != _zoomLevel) {
|
|
||||||
setState(() {
|
|
||||||
_zoomLevel = scale;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8.0, vertical: 16.0),
|
|
||||||
child: Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
for (int i = 0; i < pages.length; i++) ...[
|
|
||||||
Container(
|
|
||||||
margin: const EdgeInsets.only(bottom: 16),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.15),
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(0, 3),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Image(
|
|
||||||
image: pages[i].image,
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (pages.length > 1)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 12.0),
|
|
||||||
child: Text(
|
|
||||||
'Seite ${i + 1} von ${pages.length}',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Colors.grey.shade700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// Floating Zoom Controls Overlay
|
|
||||||
Positioned(
|
|
||||||
right: 16,
|
|
||||||
bottom: 24,
|
|
||||||
child: Card(
|
|
||||||
elevation: 4,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(24)),
|
|
||||||
color: Colors.white.withOpacity(0.92),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 2),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.zoom_in, color: Colors.black87),
|
|
||||||
tooltip: 'Vergrößern (+)',
|
|
||||||
onPressed: _zoomIn,
|
|
||||||
),
|
|
||||||
InkWell(
|
|
||||||
onTap: _resetZoom,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 4, horizontal: 6),
|
|
||||||
child: Text(
|
|
||||||
'${(_zoomLevel * 100).round()}%',
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.zoom_out, color: Colors.black87),
|
|
||||||
tooltip: 'Verkleinern (-)',
|
|
||||||
onPressed: _zoomOut,
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.restart_alt, size: 20, color: Colors.grey),
|
|
||||||
tooltip: 'Zoom zurücksetzen (1:1)',
|
|
||||||
onPressed: _resetZoom,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
|
||||||
import '../models/post_item.dart';
|
import '../models/post_item.dart';
|
||||||
import '../services/aussendungen_service.dart';
|
|
||||||
import '../services/auth_service.dart';
|
import '../services/auth_service.dart';
|
||||||
import '../services/firestore_service.dart';
|
import '../services/firestore_service.dart';
|
||||||
import '../services/pdf_service.dart';
|
import '../services/pdf_service.dart';
|
||||||
@@ -13,7 +12,6 @@ import 'add_issue_screen.dart';
|
|||||||
import 'add_post_screen.dart';
|
import 'add_post_screen.dart';
|
||||||
import 'auth_dialog.dart';
|
import 'auth_dialog.dart';
|
||||||
import 'detail_screen.dart';
|
import 'detail_screen.dart';
|
||||||
import 'pdf_viewer_screen.dart';
|
|
||||||
|
|
||||||
class PostListScreen extends StatefulWidget {
|
class PostListScreen extends StatefulWidget {
|
||||||
final String collectionName;
|
final String collectionName;
|
||||||
@@ -32,44 +30,12 @@ class PostListScreen extends StatefulWidget {
|
|||||||
class _PostListScreenState extends State<PostListScreen> {
|
class _PostListScreenState extends State<PostListScreen> {
|
||||||
final FirestoreService _firestoreService = FirestoreService();
|
final FirestoreService _firestoreService = FirestoreService();
|
||||||
final StorageService _storageService = StorageService();
|
final StorageService _storageService = StorageService();
|
||||||
final AussendungenService _aussendungenService = AussendungenService();
|
|
||||||
|
|
||||||
final Map<String, PostItem> _selectedItems = {};
|
final Map<String, PostItem> _selectedItems = {};
|
||||||
String _searchQuery = '';
|
String _searchQuery = '';
|
||||||
bool _isSearchActive = false;
|
bool _isSearchActive = false;
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
|
||||||
List<PostItem> _aussendungen = [];
|
|
||||||
bool _isLoadingAussendungen = false;
|
|
||||||
String _newsFilter = 'all'; // 'all', 'aussendungen', 'news'
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
if (widget.collectionName == 'News') {
|
|
||||||
_loadAussendungen();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadAussendungen({bool force = false}) async {
|
|
||||||
if (widget.collectionName != 'News') return;
|
|
||||||
if (mounted) setState(() => _isLoadingAussendungen = true);
|
|
||||||
try {
|
|
||||||
final items = await _aussendungenService.getAussendungen(forceRefresh: force);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
_aussendungen = items;
|
|
||||||
_isLoadingAussendungen = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error loading Aussendungen: $e');
|
|
||||||
if (mounted) {
|
|
||||||
setState(() => _isLoadingAussendungen = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_searchController.dispose();
|
_searchController.dispose();
|
||||||
@@ -93,28 +59,9 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _deletePost(PostItem item) async {
|
Future<void> _deletePost(PostItem item) async {
|
||||||
final auth = Provider.of<AuthService>(context, listen: false);
|
|
||||||
final currentUser = auth.user;
|
|
||||||
final isAuthor = currentUser != null && item.authorUid == currentUser.uid;
|
|
||||||
final canDelete = isAuthor || auth.isAdmin;
|
|
||||||
|
|
||||||
if (!canDelete) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('Keine Berechtigung zum Löschen dieses Beitrags.'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (final url in item.imageUrls) {
|
for (final url in item.imageUrls) {
|
||||||
try {
|
|
||||||
await _storageService.deleteFileByUrl(url);
|
await _storageService.deleteFileByUrl(url);
|
||||||
} catch (storageErr) {
|
|
||||||
debugPrint('Storage delete non-fatal error: $storageErr');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await _firestoreService.deletePost(widget.collectionName, item.id);
|
await _firestoreService.deletePost(widget.collectionName, item.id);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
@@ -132,18 +79,6 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
Future<void> _onAddNewPressed() async {
|
Future<void> _onAddNewPressed() async {
|
||||||
final auth = Provider.of<AuthService>(context, listen: false);
|
final auth = Provider.of<AuthService>(context, listen: false);
|
||||||
|
|
||||||
// News are official announcements and can only be created by Admins
|
|
||||||
if (widget.collectionName == 'News' && !auth.isAdmin) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content:
|
|
||||||
Text('Nur Administratoren können Neuigkeiten veröffentlichen.'),
|
|
||||||
backgroundColor: Colors.amber,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!auth.isCommunityUnlocked && !auth.isAuthenticated) {
|
if (!auth.isCommunityUnlocked && !auth.isAuthenticated) {
|
||||||
await AuthDialog.show(context);
|
await AuthDialog.show(context);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
@@ -176,8 +111,7 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final auth = Provider.of<AuthService>(context);
|
final currentUser = FirebaseAuth.instance.currentUser;
|
||||||
final currentUser = auth.user;
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@@ -246,86 +180,7 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: widget.collectionName == 'News'
|
body: StreamBuilder<List<PostItem>>(
|
||||||
? Column(
|
|
||||||
children: [
|
|
||||||
_buildNewsFilterBar(),
|
|
||||||
if (_isLoadingAussendungen && _aussendungen.isEmpty)
|
|
||||||
const LinearProgressIndicator(minHeight: 2),
|
|
||||||
Expanded(
|
|
||||||
child: RefreshIndicator(
|
|
||||||
onRefresh: () async {
|
|
||||||
await _loadAussendungen(force: true);
|
|
||||||
},
|
|
||||||
child: _buildPostList(auth, currentUser),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: _buildPostList(auth, currentUser),
|
|
||||||
floatingActionButton: (widget.collectionName == 'News' && !auth.isAdmin)
|
|
||||||
? null
|
|
||||||
: FloatingActionButton(
|
|
||||||
onPressed: _onAddNewPressed,
|
|
||||||
tooltip: widget.collectionName == 'News'
|
|
||||||
? 'Nachricht verfassen'
|
|
||||||
: 'Neuen Eintrag erstellen',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildNewsFilterBar() {
|
|
||||||
return Container(
|
|
||||||
width: double.infinity,
|
|
||||||
color: Colors.grey.shade50,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
ChoiceChip(
|
|
||||||
label: const Text('Alle'),
|
|
||||||
selected: _newsFilter == 'all',
|
|
||||||
onSelected: (_) => setState(() => _newsFilter = 'all'),
|
|
||||||
selectedColor: Colors.blue.shade100,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: Icon(
|
|
||||||
Icons.picture_as_pdf,
|
|
||||||
size: 16,
|
|
||||||
color: _newsFilter == 'aussendungen'
|
|
||||||
? Colors.red.shade900
|
|
||||||
: Colors.red.shade700,
|
|
||||||
),
|
|
||||||
label: Text('Aussendungen (${_aussendungen.length})'),
|
|
||||||
selected: _newsFilter == 'aussendungen',
|
|
||||||
onSelected: (_) => setState(() => _newsFilter = 'aussendungen'),
|
|
||||||
selectedColor: Colors.red.shade100,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: Icon(
|
|
||||||
Icons.newspaper,
|
|
||||||
size: 16,
|
|
||||||
color: _newsFilter == 'news'
|
|
||||||
? Colors.blue.shade900
|
|
||||||
: Colors.blue.shade700,
|
|
||||||
),
|
|
||||||
label: const Text('Aktuelles'),
|
|
||||||
selected: _newsFilter == 'news',
|
|
||||||
onSelected: (_) => setState(() => _newsFilter = 'news'),
|
|
||||||
selectedColor: Colors.blue.shade100,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildPostList(AuthService auth, dynamic currentUser) {
|
|
||||||
return StreamBuilder<List<PostItem>>(
|
|
||||||
stream: _firestoreService.getPostsStream(widget.collectionName),
|
stream: _firestoreService.getPostsStream(widget.collectionName),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
@@ -337,27 +192,11 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snapshot.connectionState == ConnectionState.waiting &&
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
widget.collectionName != 'News') {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
final firestoreItems = snapshot.data ?? [];
|
final allItems = snapshot.data ?? [];
|
||||||
List<PostItem> allItems;
|
|
||||||
|
|
||||||
if (widget.collectionName == 'News') {
|
|
||||||
allItems = [...firestoreItems, ..._aussendungen];
|
|
||||||
allItems.sort((a, b) => b.createdDate.compareTo(a.createdDate));
|
|
||||||
|
|
||||||
if (_newsFilter == 'aussendungen') {
|
|
||||||
allItems = allItems.where((item) => item.isAussendung).toList();
|
|
||||||
} else if (_newsFilter == 'news') {
|
|
||||||
allItems = allItems.where((item) => !item.isAussendung).toList();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
allItems = firestoreItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
final filteredItems = allItems.where((item) {
|
final filteredItems = allItems.where((item) {
|
||||||
if (_searchQuery.isEmpty) return true;
|
if (_searchQuery.isEmpty) return true;
|
||||||
final query = _searchQuery.toLowerCase();
|
final query = _searchQuery.toLowerCase();
|
||||||
@@ -401,13 +240,29 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
final isSelected = _selectedItems.containsKey(item.id);
|
final isSelected = _selectedItems.containsKey(item.id);
|
||||||
final isAuthor =
|
final isAuthor =
|
||||||
currentUser != null && item.authorUid == currentUser.uid;
|
currentUser != null && item.authorUid == currentUser.uid;
|
||||||
final canDelete = !item.isAussendung && (isAuthor || auth.isAdmin);
|
|
||||||
final formattedDate =
|
final formattedDate =
|
||||||
DateFormat('dd.MM.yyyy').format(item.createdDate);
|
DateFormat('dd.MM.yyyy').format(item.createdDate);
|
||||||
|
|
||||||
Widget? leadingWidget;
|
Widget itemTile = ListTile(
|
||||||
if (item.imageUrl.isNotEmpty) {
|
selected: isSelected,
|
||||||
leadingWidget = Stack(
|
selectedTileColor: Colors.blue.shade50,
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
onTap: () {
|
||||||
|
if (_selectedItems.isNotEmpty) {
|
||||||
|
_toggleSelection(item);
|
||||||
|
} else {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (ctx) => DetailScreen(item: item),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () => _toggleSelection(item),
|
||||||
|
leading: item.imageUrl.isNotEmpty
|
||||||
|
? Stack(
|
||||||
children: [
|
children: [
|
||||||
ClipRRect(
|
ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
@@ -447,94 +302,12 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
)
|
||||||
} else if (item.isAussendung) {
|
: isSelected
|
||||||
leadingWidget = Stack(
|
? const CircleAvatar(
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
width: 58,
|
|
||||||
height: 58,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(color: Colors.red.shade200),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.picture_as_pdf,
|
|
||||||
color: Colors.red.shade700, size: 26),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
'PDF',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 9,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.red.shade800,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (isSelected)
|
|
||||||
const Positioned(
|
|
||||||
top: 2,
|
|
||||||
left: 2,
|
|
||||||
child: CircleAvatar(
|
|
||||||
radius: 12,
|
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
child: Icon(Icons.check, size: 16, color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else if (isSelected) {
|
|
||||||
leadingWidget = const CircleAvatar(
|
|
||||||
backgroundColor: Colors.blue,
|
backgroundColor: Colors.blue,
|
||||||
child: Icon(Icons.check, color: Colors.white),
|
child: Icon(Icons.check, color: Colors.white),
|
||||||
);
|
)
|
||||||
}
|
|
||||||
|
|
||||||
Widget itemTile = ListTile(
|
|
||||||
selected: isSelected,
|
|
||||||
selectedTileColor: Colors.blue.shade50,
|
|
||||||
contentPadding:
|
|
||||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
onTap: () async {
|
|
||||||
if (_selectedItems.isNotEmpty) {
|
|
||||||
_toggleSelection(item);
|
|
||||||
} else if (item.isAussendung) {
|
|
||||||
if (item.pdfUrl != null && item.pdfUrl!.isNotEmpty) {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (ctx) => PdfViewerScreen(
|
|
||||||
title: item.title,
|
|
||||||
pdfUrl: item.pdfUrl!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (item.webUrl != null && item.webUrl!.isNotEmpty) {
|
|
||||||
final uri = Uri.parse(item.webUrl!);
|
|
||||||
if (await canLaunchUrl(uri)) {
|
|
||||||
await launchUrl(uri,
|
|
||||||
mode: LaunchMode.externalApplication);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (ctx) => DetailScreen(item: item),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongPress: () => _toggleSelection(item),
|
|
||||||
leading: leadingWidget,
|
|
||||||
trailing: item.isAussendung
|
|
||||||
? Icon(Icons.arrow_forward_ios,
|
|
||||||
size: 14, color: Colors.grey.shade400)
|
|
||||||
: null,
|
: null,
|
||||||
title: Row(
|
title: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
@@ -546,7 +319,7 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -567,8 +340,7 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.location_on,
|
const Icon(Icons.location_on, size: 12, color: Colors.redAccent),
|
||||||
size: 12, color: Colors.redAccent),
|
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
item.street!,
|
item.street!,
|
||||||
@@ -582,40 +354,6 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
if (item.isAussendung)
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 6, vertical: 2),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red.shade100,
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
'Aussendung (PDF)',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.red.shade900,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
item.description,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.grey.shade700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Text(
|
Text(
|
||||||
item.description,
|
item.description,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
@@ -629,7 +367,7 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (canDelete) {
|
if (isAuthor) {
|
||||||
return Dismissible(
|
return Dismissible(
|
||||||
key: Key(item.id),
|
key: Key(item.id),
|
||||||
direction: DismissDirection.endToStart,
|
direction: DismissDirection.endToStart,
|
||||||
@@ -670,6 +408,12 @@ class _PostListScreenState extends State<PostListScreen> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
onPressed: _onAddNewPressed,
|
||||||
|
tooltip: 'Neuen Eintrag erstellen',
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,552 +0,0 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
import '../services/auth_service.dart';
|
|
||||||
import '../services/firestore_service.dart';
|
|
||||||
|
|
||||||
class UserManagementScreen extends StatefulWidget {
|
|
||||||
const UserManagementScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<UserManagementScreen> createState() => _UserManagementScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _UserManagementScreenState extends State<UserManagementScreen> {
|
|
||||||
final FirestoreService _firestoreService = FirestoreService();
|
|
||||||
String _searchQuery = '';
|
|
||||||
bool _isSearchActive = false;
|
|
||||||
final TextEditingController _searchController = TextEditingController();
|
|
||||||
String _selectedFilter = 'all'; // 'all', 'admins', 'citizens'
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_searchController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _toggleAdminRole({
|
|
||||||
required String uid,
|
|
||||||
required String email,
|
|
||||||
required String displayName,
|
|
||||||
required bool currentIsAdmin,
|
|
||||||
required String currentAdminUid,
|
|
||||||
}) async {
|
|
||||||
if (currentIsAdmin && uid == currentAdminUid) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Sie können sich nicht selbst die Administrator-Rechte entziehen.'),
|
|
||||||
backgroundColor: Colors.amber,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final targetAction = currentIsAdmin ? 'entziehen' : 'erteilen';
|
|
||||||
final confirmed = await showDialog<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (dCtx) => AlertDialog(
|
|
||||||
title: Text(currentIsAdmin
|
|
||||||
? 'Admin-Rechte entziehen?'
|
|
||||||
: 'Zum Administrator ernennen?'),
|
|
||||||
content: Text(currentIsAdmin
|
|
||||||
? 'Möchten Sie $displayName die Administrator-Rechte wirklich entziehen?'
|
|
||||||
: 'Möchten Sie $displayName wirklich zum Administrator ernennen? Dieser Nutzer erhält vollen Zugriff auf News, alle Beiträge, Bürgernachrichten und die Benutzerverwaltung.'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(dCtx, false),
|
|
||||||
child: const Text('Abbrechen'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor:
|
|
||||||
currentIsAdmin ? Colors.red : Colors.indigo.shade700,
|
|
||||||
),
|
|
||||||
onPressed: () => Navigator.pop(dCtx, true),
|
|
||||||
child: Text(currentIsAdmin ? 'Rechte entziehen' : 'Ernennen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (confirmed == true) {
|
|
||||||
try {
|
|
||||||
await _firestoreService.setAdminRole(
|
|
||||||
uid: uid,
|
|
||||||
email: email,
|
|
||||||
makeAdmin: !currentIsAdmin,
|
|
||||||
grantedBy: currentAdminUid,
|
|
||||||
);
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(
|
|
||||||
'Administrator-Rechte wurden erfolgreich $targetAction.'),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text('Fehler beim Ändern der Rechte: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _showAddAdminDialog(String currentAdminUid) async {
|
|
||||||
final emailController = TextEditingController();
|
|
||||||
final uidController = TextEditingController();
|
|
||||||
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (dCtx) => AlertDialog(
|
|
||||||
title: const Text('Admin manuell hinzufügen'),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Geben Sie die E-Mail-Adresse oder Firebase-UID des neuen Administrators ein:',
|
|
||||||
style: TextStyle(fontSize: 13),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
TextField(
|
|
||||||
controller: emailController,
|
|
||||||
keyboardType: TextInputType.emailAddress,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'E-Mail-Adresse *',
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
TextField(
|
|
||||||
controller: uidController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: 'UID (optional)',
|
|
||||||
hintText: 'z. B. aus Firebase Auth',
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(dCtx),
|
|
||||||
child: const Text('Abbrechen'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
final email = emailController.text.trim().toLowerCase();
|
|
||||||
final uid = uidController.text.trim();
|
|
||||||
if (email.isEmpty && uid.isEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final identifier = uid.isNotEmpty ? uid : email;
|
|
||||||
try {
|
|
||||||
await _firestoreService.addAdminDirectly(
|
|
||||||
identifier: identifier,
|
|
||||||
email: email,
|
|
||||||
grantedBy: currentAdminUid,
|
|
||||||
);
|
|
||||||
if (dCtx.mounted) {
|
|
||||||
Navigator.pop(dCtx);
|
|
||||||
}
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('Administrator erfolgreich hinzugefügt.'),
|
|
||||||
backgroundColor: Colors.green,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text('Fehler beim Hinzufügen: $e'),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Text('Hinzufügen'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final auth = Provider.of<AuthService>(context);
|
|
||||||
final currentAdminUid = auth.user?.uid ?? '';
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: _isSearchActive
|
|
||||||
? TextField(
|
|
||||||
controller: _searchController,
|
|
||||||
autofocus: true,
|
|
||||||
style: const TextStyle(color: Colors.black87),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Benutzer nach Name oder E-Mail suchen...',
|
|
||||||
border: InputBorder.none,
|
|
||||||
hintStyle: TextStyle(color: Colors.grey.shade600),
|
|
||||||
),
|
|
||||||
onChanged: (val) => setState(() => _searchQuery = val.trim()),
|
|
||||||
)
|
|
||||||
: const Text('Benutzerverwaltung'),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(_isSearchActive ? Icons.close : Icons.search),
|
|
||||||
tooltip: _isSearchActive ? 'Suche beenden' : 'Suchen',
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
if (_isSearchActive) {
|
|
||||||
_isSearchActive = false;
|
|
||||||
_searchQuery = '';
|
|
||||||
_searchController.clear();
|
|
||||||
} else {
|
|
||||||
_isSearchActive = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.person_add_alt_1),
|
|
||||||
tooltip: 'Admin manuell hinzufügen',
|
|
||||||
onPressed: () => _showAddAdminDialog(currentAdminUid),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
// Filter Chips
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
color: Colors.grey.shade50,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
ChoiceChip(
|
|
||||||
label: const Text('Alle'),
|
|
||||||
selected: _selectedFilter == 'all',
|
|
||||||
onSelected: (_) => setState(() => _selectedFilter = 'all'),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: const Icon(Icons.admin_panel_settings,
|
|
||||||
size: 16, color: Colors.indigo),
|
|
||||||
label: const Text('Administratoren'),
|
|
||||||
selected: _selectedFilter == 'admins',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'admins'),
|
|
||||||
selectedColor: Colors.indigo.shade100,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
ChoiceChip(
|
|
||||||
avatar: const Icon(Icons.person_outline,
|
|
||||||
size: 16, color: Colors.teal),
|
|
||||||
label: const Text('Bürger'),
|
|
||||||
selected: _selectedFilter == 'citizens',
|
|
||||||
onSelected: (_) =>
|
|
||||||
setState(() => _selectedFilter = 'citizens'),
|
|
||||||
selectedColor: Colors.teal.shade100,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Users and Admins Stream
|
|
||||||
Expanded(
|
|
||||||
child: StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
|
|
||||||
stream: _firestoreService.getAdminsStream(),
|
|
||||||
builder: (context, adminSnapshot) {
|
|
||||||
final Set<String> adminUids = {};
|
|
||||||
final Set<String> adminEmails = {};
|
|
||||||
|
|
||||||
if (adminSnapshot.hasData) {
|
|
||||||
for (final doc in adminSnapshot.data!.docs) {
|
|
||||||
adminUids.add(doc.id.toLowerCase());
|
|
||||||
final data = doc.data();
|
|
||||||
final email =
|
|
||||||
(data['email'] as String? ?? '').toLowerCase();
|
|
||||||
if (email.isNotEmpty) adminEmails.add(email);
|
|
||||||
final uid =
|
|
||||||
(data['uid'] as String? ?? '').toLowerCase();
|
|
||||||
if (uid.isNotEmpty) adminUids.add(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
|
|
||||||
stream: _firestoreService.getUsersStream(),
|
|
||||||
builder: (context, userSnapshot) {
|
|
||||||
if (userSnapshot.hasError) {
|
|
||||||
return Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(24.0),
|
|
||||||
child: Text(
|
|
||||||
'Fehler beim Laden der Benutzer: ${userSnapshot.error}',
|
|
||||||
style: const TextStyle(color: Colors.red),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userSnapshot.connectionState ==
|
|
||||||
ConnectionState.waiting) {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
|
|
||||||
final userDocs = userSnapshot.data?.docs ?? [];
|
|
||||||
final filteredUsers = userDocs.where((doc) {
|
|
||||||
final data = doc.data();
|
|
||||||
final uid = doc.id;
|
|
||||||
final email =
|
|
||||||
(data['email'] as String? ?? '').toLowerCase();
|
|
||||||
final isUserAdmin = adminUids.contains(uid.toLowerCase()) ||
|
|
||||||
adminEmails.contains(email) ||
|
|
||||||
data['isAdmin'] == true;
|
|
||||||
|
|
||||||
if (_selectedFilter == 'admins' && !isUserAdmin) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_selectedFilter == 'citizens' && isUserAdmin) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_searchQuery.isNotEmpty) {
|
|
||||||
final q = _searchQuery.toLowerCase();
|
|
||||||
final name =
|
|
||||||
(data['displayName'] as String? ?? '').toLowerCase();
|
|
||||||
final fn =
|
|
||||||
(data['firstName'] as String? ?? '').toLowerCase();
|
|
||||||
final ln =
|
|
||||||
(data['lastName'] as String? ?? '').toLowerCase();
|
|
||||||
return name.contains(q) ||
|
|
||||||
email.contains(q) ||
|
|
||||||
fn.contains(q) ||
|
|
||||||
ln.contains(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
if (filteredUsers.isEmpty) {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.people_outline,
|
|
||||||
size: 64, color: Colors.grey.shade400),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Text(
|
|
||||||
_searchQuery.isNotEmpty
|
|
||||||
? 'Keine Treffer für "$_searchQuery"'
|
|
||||||
: 'Noch keine registrierten Benutzer vorhanden.',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListView.separated(
|
|
||||||
itemCount: filteredUsers.length,
|
|
||||||
separatorBuilder: (ctx, i) => const Divider(height: 1),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final doc = filteredUsers[index];
|
|
||||||
final data = doc.data();
|
|
||||||
final uid = doc.id;
|
|
||||||
final email = data['email'] as String? ?? '';
|
|
||||||
final displayName = data['displayName'] as String? ??
|
|
||||||
'${data['firstName'] ?? ''} ${data['lastName'] ?? ''}'.trim();
|
|
||||||
final name = displayName.isNotEmpty
|
|
||||||
? displayName
|
|
||||||
: (email.isNotEmpty ? email : 'Bürger');
|
|
||||||
final isCurrentUser = uid == currentAdminUid;
|
|
||||||
final isUserAdmin =
|
|
||||||
adminUids.contains(uid.toLowerCase()) ||
|
|
||||||
adminEmails.contains(email.toLowerCase()) ||
|
|
||||||
data['isAdmin'] == true;
|
|
||||||
|
|
||||||
DateTime? createdAt;
|
|
||||||
if (data['createdAt'] is Timestamp) {
|
|
||||||
createdAt = (data['createdAt'] as Timestamp).toDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListTile(
|
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 16, vertical: 8),
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor: isUserAdmin
|
|
||||||
? Colors.indigo.shade100
|
|
||||||
: Colors.blue.shade50,
|
|
||||||
child: Icon(
|
|
||||||
isUserAdmin
|
|
||||||
? Icons.admin_panel_settings
|
|
||||||
: Icons.person,
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.indigo.shade800
|
|
||||||
: Colors.blue.shade700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
title: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
name,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (isCurrentUser) ...[
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 6, vertical: 2),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
child: const Text(
|
|
||||||
'Du',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
subtitle: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (email.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(
|
|
||||||
email,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.grey.shade700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8, vertical: 2),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.indigo.shade50
|
|
||||||
: Colors.teal.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
border: Border.all(
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.indigo.shade200
|
|
||||||
: Colors.teal.shade200,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
isUserAdmin ? 'Administrator' : 'Bürger',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.indigo.shade800
|
|
||||||
: Colors.teal.shade800,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (createdAt != null) ...[
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text(
|
|
||||||
'Seit ${DateFormat('dd.MM.yyyy').format(createdAt)}',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11,
|
|
||||||
color: Colors.grey.shade500,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
trailing: PopupMenuButton<String>(
|
|
||||||
icon: const Icon(Icons.more_vert),
|
|
||||||
tooltip: 'Optionen',
|
|
||||||
onSelected: (action) {
|
|
||||||
if (action == 'toggleAdmin') {
|
|
||||||
_toggleAdminRole(
|
|
||||||
uid: uid,
|
|
||||||
email: email,
|
|
||||||
displayName: name,
|
|
||||||
currentIsAdmin: isUserAdmin,
|
|
||||||
currentAdminUid: currentAdminUid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (ctx) => [
|
|
||||||
PopupMenuItem(
|
|
||||||
value: 'toggleAdmin',
|
|
||||||
enabled: !(isUserAdmin && isCurrentUser),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
isUserAdmin
|
|
||||||
? Icons.remove_moderator
|
|
||||||
: Icons.add_moderator,
|
|
||||||
size: 20,
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.red
|
|
||||||
: Colors.indigo.shade700,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Text(
|
|
||||||
isUserAdmin
|
|
||||||
? 'Admin-Rechte entziehen'
|
|
||||||
: 'Zum Admin ernennen',
|
|
||||||
style: TextStyle(
|
|
||||||
color: isUserAdmin
|
|
||||||
? Colors.red
|
|
||||||
: Colors.indigo.shade700,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import '../models/post_item.dart';
|
|
||||||
|
|
||||||
class AussendungenService {
|
|
||||||
static const String _cacheKey = 'cached_aussendungen_v1';
|
|
||||||
static const String _apiUrl =
|
|
||||||
'https://buergerforumoggau.at/wp-json/wp/v2/posts?categories=9&per_page=50';
|
|
||||||
|
|
||||||
static List<PostItem>? _memoryCache;
|
|
||||||
|
|
||||||
/// Returns cached posts immediately if available, followed by fresh network posts
|
|
||||||
Future<List<PostItem>> getAussendungen({bool forceRefresh = false}) async {
|
|
||||||
if (!forceRefresh && _memoryCache != null && _memoryCache!.isNotEmpty) {
|
|
||||||
return _memoryCache!;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try loading from local SharedPreferences cache first
|
|
||||||
if (!forceRefresh) {
|
|
||||||
final cached = await _loadFromLocalCache();
|
|
||||||
if (cached.isNotEmpty) {
|
|
||||||
_memoryCache = cached;
|
|
||||||
// Trigger background refresh silently
|
|
||||||
_fetchFromNetworkAndCache().catchError((e) {
|
|
||||||
debugPrint('Silent background refresh failed: ');
|
|
||||||
return <PostItem>[];
|
|
||||||
});
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise fetch fresh from network
|
|
||||||
try {
|
|
||||||
final fresh = await _fetchFromNetworkAndCache();
|
|
||||||
if (fresh.isNotEmpty) {
|
|
||||||
_memoryCache = fresh;
|
|
||||||
return fresh;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Aussendungen network fetch error: ');
|
|
||||||
final fallback = await _loadFromLocalCache();
|
|
||||||
if (fallback.isNotEmpty) {
|
|
||||||
_memoryCache = fallback;
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _memoryCache ?? [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Network request to WordPress REST API
|
|
||||||
Future<List<PostItem>> _fetchFromNetworkAndCache() async {
|
|
||||||
final response = await http
|
|
||||||
.get(Uri.parse(_apiUrl))
|
|
||||||
.timeout(const Duration(seconds: 10));
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
final dynamic decoded = jsonDecode(utf8.decode(response.bodyBytes));
|
|
||||||
if (decoded is List) {
|
|
||||||
final List<PostItem> items = [];
|
|
||||||
for (final item in decoded) {
|
|
||||||
if (item is Map<String, dynamic>) {
|
|
||||||
try {
|
|
||||||
final post = PostItem.fromWordPressJson(item);
|
|
||||||
items.add(post);
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error parsing WP post item: ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await _saveToLocalCache(decoded);
|
|
||||||
_memoryCache = items;
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw Exception('Server returned ');
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load from SharedPreferences
|
|
||||||
Future<List<PostItem>> _loadFromLocalCache() async {
|
|
||||||
try {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
final String? jsonString = prefs.getString(_cacheKey);
|
|
||||||
if (jsonString != null && jsonString.isNotEmpty) {
|
|
||||||
final dynamic decoded = jsonDecode(jsonString);
|
|
||||||
if (decoded is List) {
|
|
||||||
final List<PostItem> items = [];
|
|
||||||
for (final item in decoded) {
|
|
||||||
if (item is Map<String, dynamic>) {
|
|
||||||
try {
|
|
||||||
items.add(PostItem.fromWordPressJson(item));
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error parsing cached WP item: ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error loading cached aussendungen: ');
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Save to SharedPreferences
|
|
||||||
Future<void> _saveToLocalCache(List<dynamic> jsonList) async {
|
|
||||||
try {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString(_cacheKey, jsonEncode(jsonList));
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error saving aussendungen to cache: ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class AuthService extends ChangeNotifier {
|
class AuthService extends ChangeNotifier {
|
||||||
@@ -19,112 +18,16 @@ class AuthService extends ChangeNotifier {
|
|||||||
String? get email => _user?.email;
|
String? get email => _user?.email;
|
||||||
String? get displayName => _user?.displayName;
|
String? get displayName => _user?.displayName;
|
||||||
|
|
||||||
String? _cachedFirstName;
|
|
||||||
String? _cachedLastName;
|
|
||||||
bool _isAdmin = false;
|
|
||||||
bool get isAdmin => _isAdmin;
|
|
||||||
|
|
||||||
String get firstName {
|
|
||||||
if (_cachedFirstName != null && _cachedFirstName!.isNotEmpty) {
|
|
||||||
return _cachedFirstName!;
|
|
||||||
}
|
|
||||||
final name = _user?.displayName ?? '';
|
|
||||||
if (name.isEmpty) return '';
|
|
||||||
final parts = name.trim().split(RegExp(r'\s+'));
|
|
||||||
return parts.isNotEmpty ? parts.first : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
String get lastName {
|
|
||||||
if (_cachedLastName != null && _cachedLastName!.isNotEmpty) {
|
|
||||||
return _cachedLastName!;
|
|
||||||
}
|
|
||||||
final name = _user?.displayName ?? '';
|
|
||||||
if (name.isEmpty) return '';
|
|
||||||
final parts = name.trim().split(RegExp(r'\s+'));
|
|
||||||
return parts.length > 1 ? parts.sublist(1).join(' ') : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthService() {
|
AuthService() {
|
||||||
_initAuth();
|
_initAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _checkAdminClaim(User? user) async {
|
|
||||||
if (user != null && !user.isAnonymous) {
|
|
||||||
try {
|
|
||||||
// 1. Custom claims check (token.admin == true)
|
|
||||||
final tokenResult = await user.getIdTokenResult();
|
|
||||||
if (tokenResult.claims?['admin'] == true) {
|
|
||||||
_isAdmin = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final firestore = FirebaseFirestore.instance;
|
|
||||||
|
|
||||||
// 2. Check Firestore 'Admins' collection by user UID (doc id)
|
|
||||||
final docByUid =
|
|
||||||
await firestore.collection('Admins').doc(user.uid).get();
|
|
||||||
if (docByUid.exists) {
|
|
||||||
_isAdmin = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Check Firestore 'Admins' collection by email (doc id)
|
|
||||||
final userEmail = user.email?.trim().toLowerCase();
|
|
||||||
if (userEmail != null && userEmail.isNotEmpty) {
|
|
||||||
final docByEmail =
|
|
||||||
await firestore.collection('Admins').doc(userEmail).get();
|
|
||||||
if (docByEmail.exists) {
|
|
||||||
_isAdmin = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Check Firestore 'Admins' collection where email field == userEmail
|
|
||||||
final queryByEmail = await firestore
|
|
||||||
.collection('Admins')
|
|
||||||
.where('email', isEqualTo: userEmail)
|
|
||||||
.limit(1)
|
|
||||||
.get();
|
|
||||||
if (queryByEmail.docs.isNotEmpty) {
|
|
||||||
_isAdmin = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. Check Firestore 'Admins' collection where uid field == user.uid
|
|
||||||
final queryByUid = await firestore
|
|
||||||
.collection('Admins')
|
|
||||||
.where('uid', isEqualTo: user.uid)
|
|
||||||
.limit(1)
|
|
||||||
.get();
|
|
||||||
if (queryByUid.docs.isNotEmpty) {
|
|
||||||
_isAdmin = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_isAdmin = false;
|
|
||||||
} catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
debugPrint('Error checking admin status: $e');
|
|
||||||
}
|
|
||||||
_isAdmin = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_isAdmin = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _initAuth() async {
|
Future<void> _initAuth() async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
_isCommunityUnlocked = prefs.getBool(_prefKeyUnlocked) ?? false;
|
_isCommunityUnlocked = prefs.getBool(_prefKeyUnlocked) ?? false;
|
||||||
_cachedFirstName = prefs.getString('user_first_name');
|
|
||||||
_cachedLastName = prefs.getString('user_last_name');
|
|
||||||
|
|
||||||
_auth.authStateChanges().listen((User? user) async {
|
_auth.authStateChanges().listen((User? user) {
|
||||||
_user = user;
|
_user = user;
|
||||||
await _checkAdminClaim(user);
|
|
||||||
if (user != null && !user.isAnonymous) {
|
|
||||||
await _syncUserProfile(user);
|
|
||||||
}
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -133,33 +36,6 @@ class AuthService extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _syncUserProfile(User user, {String? firstName, String? lastName}) async {
|
|
||||||
if (user.isAnonymous) return;
|
|
||||||
try {
|
|
||||||
final cleanEmail = user.email?.trim().toLowerCase() ?? '';
|
|
||||||
if (cleanEmail.isEmpty) return;
|
|
||||||
|
|
||||||
final cleanFirst = firstName ?? this.firstName;
|
|
||||||
final cleanLast = lastName ?? this.lastName;
|
|
||||||
final name = user.displayName ?? '$cleanFirst $cleanLast'.trim();
|
|
||||||
|
|
||||||
await FirebaseFirestore.instance.collection('Users').doc(user.uid).set({
|
|
||||||
'uid': user.uid,
|
|
||||||
'email': cleanEmail,
|
|
||||||
'displayName': name,
|
|
||||||
'firstName': cleanFirst,
|
|
||||||
'lastName': cleanLast,
|
|
||||||
'emailVerified': user.emailVerified,
|
|
||||||
'lastLogin': FieldValue.serverTimestamp(),
|
|
||||||
if (_isAdmin) 'isAdmin': true,
|
|
||||||
}, SetOptions(merge: true));
|
|
||||||
} catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
debugPrint('Error syncing user profile in auth service: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verifies community access code
|
/// Verifies community access code
|
||||||
Future<bool> verifyCommunityCode(String enteredCode) async {
|
Future<bool> verifyCommunityCode(String enteredCode) async {
|
||||||
final cleanCode = enteredCode.trim().toLowerCase();
|
final cleanCode = enteredCode.trim().toLowerCase();
|
||||||
@@ -195,10 +71,6 @@ class AuthService extends ChangeNotifier {
|
|||||||
password: password,
|
password: password,
|
||||||
);
|
);
|
||||||
_user = credential.user;
|
_user = credential.user;
|
||||||
await _checkAdminClaim(_user);
|
|
||||||
if (_user != null) {
|
|
||||||
await _syncUserProfile(_user!);
|
|
||||||
}
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return null; // success
|
return null; // success
|
||||||
} on FirebaseAuthException catch (e) {
|
} on FirebaseAuthException catch (e) {
|
||||||
@@ -208,12 +80,11 @@ class AuthService extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign up with Email, Password, First Name, and Last Name
|
/// Sign up with Email, Password, and Full Name
|
||||||
Future<String?> signUpWithEmail({
|
Future<String?> signUpWithEmail({
|
||||||
required String email,
|
required String email,
|
||||||
required String password,
|
required String password,
|
||||||
required String firstName,
|
required String name,
|
||||||
required String lastName,
|
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final credential = await _auth.createUserWithEmailAndPassword(
|
final credential = await _auth.createUserWithEmailAndPassword(
|
||||||
@@ -221,31 +92,8 @@ class AuthService extends ChangeNotifier {
|
|||||||
password: password,
|
password: password,
|
||||||
);
|
);
|
||||||
_user = credential.user;
|
_user = credential.user;
|
||||||
if (_user != null) {
|
if (_user != null && name.isNotEmpty) {
|
||||||
final cleanFirst = firstName.trim();
|
await _user!.updateDisplayName(name.trim());
|
||||||
final cleanLast = lastName.trim();
|
|
||||||
final fullName = '$cleanFirst $cleanLast'.trim();
|
|
||||||
if (fullName.isNotEmpty) {
|
|
||||||
await _user!.updateDisplayName(fullName);
|
|
||||||
}
|
|
||||||
_cachedFirstName = cleanFirst;
|
|
||||||
_cachedLastName = cleanLast;
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setString('user_first_name', cleanFirst);
|
|
||||||
await prefs.setString('user_last_name', cleanLast);
|
|
||||||
|
|
||||||
await _checkAdminClaim(_user);
|
|
||||||
await _syncUserProfile(_user!,
|
|
||||||
firstName: cleanFirst, lastName: cleanLast);
|
|
||||||
|
|
||||||
// Send email verification so user verifies they own the email address
|
|
||||||
try {
|
|
||||||
await _user!.sendEmailVerification();
|
|
||||||
} catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
debugPrint('Error sending verification email: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return null; // success
|
return null; // success
|
||||||
@@ -256,36 +104,6 @@ class AuthService extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if user's email is verified
|
|
||||||
bool get isEmailVerified => _user?.emailVerified ?? false;
|
|
||||||
|
|
||||||
/// Reload current user from Firebase to refresh emailVerified status and admin claim
|
|
||||||
Future<void> reloadUser() async {
|
|
||||||
await _user?.reload();
|
|
||||||
_user = _auth.currentUser;
|
|
||||||
await _checkAdminClaim(_user);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Re-send verification email
|
|
||||||
Future<String?> sendEmailVerification() async {
|
|
||||||
try {
|
|
||||||
await _user?.sendEmailVerification();
|
|
||||||
return null;
|
|
||||||
} on FirebaseAuthException catch (e) {
|
|
||||||
return _getLocalizedErrorMessage(e.code);
|
|
||||||
} catch (e) {
|
|
||||||
return 'Fehler beim Senden der Bestätigungs-E-Mail: $e';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sign in with Google (UI stub / preparation)
|
|
||||||
Future<String?> signInWithGoogle() async {
|
|
||||||
// Note: Once SHA-1 fingerprint is registered in Firebase Console,
|
|
||||||
// the full interactive Google OAuth sign-in flow can be activated.
|
|
||||||
return 'Google Sign-In ist in Vorbereitung. Bitte nutze derzeit die E-Mail-Anmeldung oder den Bürger-Code.';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Send password reset email
|
/// Send password reset email
|
||||||
Future<String?> sendPasswordReset(String email) async {
|
Future<String?> sendPasswordReset(String email) async {
|
||||||
try {
|
try {
|
||||||
@@ -312,12 +130,6 @@ class AuthService extends ChangeNotifier {
|
|||||||
/// Sign out
|
/// Sign out
|
||||||
Future<void> signOut() async {
|
Future<void> signOut() async {
|
||||||
try {
|
try {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.remove('user_first_name');
|
|
||||||
await prefs.remove('user_last_name');
|
|
||||||
_cachedFirstName = null;
|
|
||||||
_cachedLastName = null;
|
|
||||||
_isAdmin = false;
|
|
||||||
await _auth.signOut();
|
await _auth.signOut();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class FirestoreService {
|
|||||||
required String email,
|
required String email,
|
||||||
String? phone,
|
String? phone,
|
||||||
required String message,
|
required String message,
|
||||||
String? authorUid,
|
|
||||||
}) async {
|
}) async {
|
||||||
await _firestore.collection('ContactMessages').add({
|
await _firestore.collection('ContactMessages').add({
|
||||||
'firstName': firstName,
|
'firstName': firstName,
|
||||||
@@ -58,143 +57,8 @@ class FirestoreService {
|
|||||||
'email': email,
|
'email': email,
|
||||||
'phone': phone ?? '',
|
'phone': phone ?? '',
|
||||||
'message': message,
|
'message': message,
|
||||||
'author_uid': authorUid ?? '',
|
|
||||||
'createdDate': Timestamp.now(),
|
'createdDate': Timestamp.now(),
|
||||||
'status': 'Neu',
|
'status': 'Neu',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stream of all contact messages (for admins)
|
|
||||||
Stream<QuerySnapshot<Map<String, dynamic>>> getContactMessagesStream() {
|
|
||||||
return _firestore
|
|
||||||
.collection('ContactMessages')
|
|
||||||
.orderBy('createdDate', descending: true)
|
|
||||||
.snapshots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the status of a contact message
|
|
||||||
Future<void> updateContactMessageStatus(String docId, String status) async {
|
|
||||||
await _firestore.collection('ContactMessages').doc(docId).update({
|
|
||||||
'status': status,
|
|
||||||
'statusUpdatedAt': FieldValue.serverTimestamp(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Delete a contact message
|
|
||||||
Future<void> deleteContactMessage(String docId) async {
|
|
||||||
await _firestore.collection('ContactMessages').doc(docId).delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stream of all registered users
|
|
||||||
Stream<QuerySnapshot<Map<String, dynamic>>> getUsersStream() {
|
|
||||||
return _firestore.collection('Users').snapshots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stream of all admin documents
|
|
||||||
Stream<QuerySnapshot<Map<String, dynamic>>> getAdminsStream() {
|
|
||||||
return _firestore.collection('Admins').snapshots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Upsert a registered user profile into Firestore
|
|
||||||
Future<void> syncUserProfile({
|
|
||||||
required String uid,
|
|
||||||
required String email,
|
|
||||||
String? displayName,
|
|
||||||
String? firstName,
|
|
||||||
String? lastName,
|
|
||||||
bool? emailVerified,
|
|
||||||
bool? isAdmin,
|
|
||||||
}) async {
|
|
||||||
try {
|
|
||||||
final docRef = _firestore.collection('Users').doc(uid);
|
|
||||||
final doc = await docRef.get();
|
|
||||||
final data = <String, dynamic>{
|
|
||||||
'uid': uid,
|
|
||||||
'email': email.trim().toLowerCase(),
|
|
||||||
'lastLogin': FieldValue.serverTimestamp(),
|
|
||||||
if (displayName != null && displayName.isNotEmpty)
|
|
||||||
'displayName': displayName,
|
|
||||||
if (firstName != null && firstName.isNotEmpty)
|
|
||||||
'firstName': firstName,
|
|
||||||
if (lastName != null && lastName.isNotEmpty)
|
|
||||||
'lastName': lastName,
|
|
||||||
if (emailVerified != null) 'emailVerified': emailVerified,
|
|
||||||
if (isAdmin != null) 'isAdmin': isAdmin,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!doc.exists) {
|
|
||||||
data['createdAt'] = FieldValue.serverTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
await docRef.set(data, SetOptions(merge: true));
|
|
||||||
} catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
debugPrint('Error syncing user profile to Firestore: $e');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Promote or demote a user to Admin in Firestore
|
|
||||||
Future<void> setAdminRole({
|
|
||||||
required String uid,
|
|
||||||
required String email,
|
|
||||||
required bool makeAdmin,
|
|
||||||
String? grantedBy,
|
|
||||||
}) async {
|
|
||||||
final cleanEmail = email.trim().toLowerCase();
|
|
||||||
final adminRef = _firestore.collection('Admins').doc(uid);
|
|
||||||
final userRef = _firestore.collection('Users').doc(uid);
|
|
||||||
|
|
||||||
if (makeAdmin) {
|
|
||||||
// 1. Add UID to Admins collection
|
|
||||||
await adminRef.set({
|
|
||||||
'uid': uid,
|
|
||||||
'email': cleanEmail,
|
|
||||||
'grantedAt': FieldValue.serverTimestamp(),
|
|
||||||
'grantedBy': grantedBy ?? '',
|
|
||||||
}, SetOptions(merge: true));
|
|
||||||
|
|
||||||
// 2. Also ensure email doc exists if email is known
|
|
||||||
if (cleanEmail.isNotEmpty) {
|
|
||||||
await _firestore.collection('Admins').doc(cleanEmail).set({
|
|
||||||
'uid': uid,
|
|
||||||
'email': cleanEmail,
|
|
||||||
'grantedAt': FieldValue.serverTimestamp(),
|
|
||||||
'grantedBy': grantedBy ?? '',
|
|
||||||
}, SetOptions(merge: true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Mark user document as admin
|
|
||||||
await userRef.set({'isAdmin': true}, SetOptions(merge: true));
|
|
||||||
} else {
|
|
||||||
// 1. Remove UID from Admins collection
|
|
||||||
await adminRef.delete();
|
|
||||||
|
|
||||||
// 2. Remove email from Admins collection if present
|
|
||||||
if (cleanEmail.isNotEmpty) {
|
|
||||||
try {
|
|
||||||
await _firestore.collection('Admins').doc(cleanEmail).delete();
|
|
||||||
} catch (_) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Update user document
|
|
||||||
await userRef.set({'isAdmin': false}, SetOptions(merge: true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add admin directly by UID or email (e.g. manual entry)
|
|
||||||
Future<void> addAdminDirectly({
|
|
||||||
required String identifier,
|
|
||||||
required String email,
|
|
||||||
String? grantedBy,
|
|
||||||
}) async {
|
|
||||||
final cleanId = identifier.trim();
|
|
||||||
final cleanEmail = email.trim().toLowerCase();
|
|
||||||
await _firestore.collection('Admins').doc(cleanId).set({
|
|
||||||
'uid': cleanId,
|
|
||||||
'email': cleanEmail,
|
|
||||||
'grantedAt': FieldValue.serverTimestamp(),
|
|
||||||
'grantedBy': grantedBy ?? '',
|
|
||||||
}, SetOptions(merge: true));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -829,70 +829,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.2"
|
version: "1.3.2"
|
||||||
url_launcher:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: url_launcher
|
|
||||||
sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.3.1"
|
|
||||||
url_launcher_android:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_android
|
|
||||||
sha256: "17cd5e205ea615e2c6ea7a77323a11712dffa0720a8a90540db57a01347f9ad9"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.3.2"
|
|
||||||
url_launcher_ios:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_ios
|
|
||||||
sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.3.2"
|
|
||||||
url_launcher_linux:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_linux
|
|
||||||
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.2.1"
|
|
||||||
url_launcher_macos:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_macos
|
|
||||||
sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.2.2"
|
|
||||||
url_launcher_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_platform_interface
|
|
||||||
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.2"
|
|
||||||
url_launcher_web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_web
|
|
||||||
sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.3.3"
|
|
||||||
url_launcher_windows:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: url_launcher_windows
|
|
||||||
sha256: "44cf3aabcedde30f2dba119a9dea3b0f2672fbe6fa96e85536251d678216b3c4"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.1.3"
|
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
+1
-2
@@ -21,7 +21,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=2.18.2 <3.0.0'
|
||||||
|
|
||||||
# Dependencies specify other packages that your package needs in order to work.
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
# To automatically upgrade your package dependencies to the latest versions
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
@@ -54,7 +54,6 @@ dependencies:
|
|||||||
provider: ^6.0.5
|
provider: ^6.0.5
|
||||||
http: ^1.2.0
|
http: ^1.2.0
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
url_launcher: ^6.3.1
|
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
const https = require('https');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const PROJECT_ID = 'gemeinde-trommler';
|
|
||||||
const COLLECTIONS = ['News', 'Issues', 'CitizensForum', 'ContactMessages', 'Admins'];
|
|
||||||
|
|
||||||
function fetchCollection(collection) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const url = `https://firestore.googleapis.com/v1/projects/${PROJECT_ID}/databases/(default)/documents/${collection}?pageSize=300`;
|
|
||||||
https.get(url, (res) => {
|
|
||||||
let raw = '';
|
|
||||||
res.on('data', (chunk) => raw += chunk);
|
|
||||||
res.on('end', () => {
|
|
||||||
try {
|
|
||||||
const json = JSON.parse(raw);
|
|
||||||
if (json.documents) {
|
|
||||||
resolve({ collection, status: 'OK', count: json.documents.length, documents: json.documents });
|
|
||||||
} else if (json.error) {
|
|
||||||
resolve({ collection, status: 'PERMISSION_OR_EMPTY', error: json.error.message, documents: [] });
|
|
||||||
} else {
|
|
||||||
resolve({ collection, status: 'EMPTY', count: 0, documents: [] });
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
resolve({ collection, status: 'PARSE_ERROR', error: e.message, documents: [] });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}).on('error', (err) => {
|
|
||||||
resolve({ collection, status: 'NETWORK_ERROR', error: err.message, documents: [] });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runBackup() {
|
|
||||||
console.log(`[Backup] Starte Sicherung fuer Firebase Projekt: ${PROJECT_ID}...`);
|
|
||||||
const results = {};
|
|
||||||
const backupDir = path.join(__dirname, '..', 'backups');
|
|
||||||
if (!fs.existsSync(backupDir)) {
|
|
||||||
fs.mkdirSync(backupDir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const col of COLLECTIONS) {
|
|
||||||
process.stdout.write(`[Backup] Lade ${col}... `);
|
|
||||||
const res = await fetchCollection(col);
|
|
||||||
results[col] = res;
|
|
||||||
console.log(`${res.status} (${res.documents ? res.documents.length : 0} Dokumente)`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
||||||
const filename = `firestore_backup_${timestamp}.json`;
|
|
||||||
const filePath = path.join(backupDir, filename);
|
|
||||||
|
|
||||||
fs.writeFileSync(filePath, JSON.stringify(results, null, 2), 'utf-8');
|
|
||||||
console.log(`\n[Backup] Erfolgreich gespeichert in: ${filePath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
runBackup();
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const token = process.env.GITEA_TOKEN;
|
|
||||||
const repo = process.env.REPO;
|
|
||||||
let apiUrl = (process.env.GITEA_API || 'https://git.djnizz.at/api/v1').replace(/\/$/, '');
|
|
||||||
if (!apiUrl.includes('/api/v1')) {
|
|
||||||
apiUrl += '/api/v1';
|
|
||||||
}
|
|
||||||
const tag = process.env.RELEASE_TAG || 'latest';
|
|
||||||
const apksDir = path.resolve('release-apks');
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
console.log('No GITEA_TOKEN provided, skipping direct release publishing.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(apksDir)) {
|
|
||||||
console.log('No release-apks directory found, skipping.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const apkFiles = fs.readdirSync(apksDir).filter(f => f.endsWith('.apk'));
|
|
||||||
if (apkFiles.length === 0) {
|
|
||||||
console.log('No APK files found in release-apks, skipping.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Publishing ${apkFiles.length} APK(s) to Gitea release tag '${tag}'...`);
|
|
||||||
|
|
||||||
// 1. Get or create release
|
|
||||||
let release = null;
|
|
||||||
const tagRes = await fetch(`${apiUrl}/repos/${repo}/releases/tags/${tag}`, {
|
|
||||||
headers: { 'Authorization': `token ${token}` }
|
|
||||||
});
|
|
||||||
|
|
||||||
if (tagRes.ok) {
|
|
||||||
release = await tagRes.json();
|
|
||||||
console.log(`Found existing release (ID: ${release.id}) for tag '${tag}'.`);
|
|
||||||
} else {
|
|
||||||
console.log(`Release for tag '${tag}' does not exist, creating new release...`);
|
|
||||||
const createRes = await fetch(`${apiUrl}/repos/${repo}/releases`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': `token ${token}`,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
tag_name: tag,
|
|
||||||
name: `Oggauer Gemeindetrommler - ${tag.toUpperCase()}`,
|
|
||||||
body: `Automatische Builds der Android APKs (Split per ABI).\nDirekte APK-Downloads ohne ZIP.`,
|
|
||||||
draft: false,
|
|
||||||
prerelease: false
|
|
||||||
})
|
|
||||||
});
|
|
||||||
if (!createRes.ok) {
|
|
||||||
console.warn(`Could not create release: ${createRes.status} ${await createRes.text()}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
release = await createRes.json();
|
|
||||||
console.log(`Created release with ID ${release.id}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Query existing assets to delete duplicates
|
|
||||||
const assetsRes = await fetch(`${apiUrl}/repos/${repo}/releases/${release.id}/assets`, {
|
|
||||||
headers: { 'Authorization': `token ${token}` }
|
|
||||||
});
|
|
||||||
const existingAssets = assetsRes.ok ? await assetsRes.json() : [];
|
|
||||||
|
|
||||||
// 3. Upload each APK
|
|
||||||
for (const fileName of apkFiles) {
|
|
||||||
const filePath = path.join(apksDir, fileName);
|
|
||||||
const existing = existingAssets.find(a => a.name === fileName);
|
|
||||||
if (existing) {
|
|
||||||
console.log(`Deleting old asset ${fileName} (ID: ${existing.id})...`);
|
|
||||||
await fetch(`${apiUrl}/repos/${repo}/releases/${release.id}/assets/${existing.id}`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: { 'Authorization': `token ${token}` }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Uploading ${fileName} (${(fs.statSync(filePath).size / (1024 * 1024)).toFixed(1)} MB)...`);
|
|
||||||
const fileBytes = fs.readFileSync(filePath);
|
|
||||||
const form = new FormData();
|
|
||||||
form.append('attachment', new Blob([fileBytes]), fileName);
|
|
||||||
|
|
||||||
const uploadRes = await fetch(`${apiUrl}/repos/${repo}/releases/${release.id}/assets?name=${encodeURIComponent(fileName)}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': `token ${token}`
|
|
||||||
},
|
|
||||||
body: form
|
|
||||||
});
|
|
||||||
|
|
||||||
if (uploadRes.ok) {
|
|
||||||
const asset = await uploadRes.json();
|
|
||||||
console.log(`✓ Uploaded ${fileName}: ${asset.browser_download_url || fileName}`);
|
|
||||||
} else {
|
|
||||||
console.warn(`Failed to upload ${fileName}: ${uploadRes.status} ${await uploadRes.text()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Finished publishing APKs to Gitea Releases!');
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch(err => {
|
|
||||||
console.error('Error in publish_release.js:', err);
|
|
||||||
});
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <spawn.h>
|
|
||||||
|
|
||||||
static int is_x86_64_elf(const char *path) {
|
|
||||||
if (!path) return 0;
|
|
||||||
int fd = open(path, O_RDONLY);
|
|
||||||
if (fd < 0) return 0;
|
|
||||||
unsigned char header[20];
|
|
||||||
ssize_t n = read(fd, header, sizeof(header));
|
|
||||||
close(fd);
|
|
||||||
if (n < 20) return 0;
|
|
||||||
if (header[0] != 0x7f || header[1] != 'E' || header[2] != 'L' || header[3] != 'F') return 0;
|
|
||||||
if (header[4] != 2 || header[5] != 1) return 0;
|
|
||||||
uint16_t machine = (uint16_t)(header[18] | (header[19] << 8));
|
|
||||||
return machine == 62;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **clean_env(char *const envp[]) {
|
|
||||||
extern char **environ;
|
|
||||||
char *const *src = envp ? envp : environ;
|
|
||||||
int count = 0;
|
|
||||||
while (src && src[count]) count++;
|
|
||||||
char **new_env = (char **)malloc((count + 1) * sizeof(char *));
|
|
||||||
if (!new_env) return (char **)src;
|
|
||||||
int j = 0;
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
if (strncmp(src[i], "LD_PRELOAD=", 11) != 0) {
|
|
||||||
new_env[j++] = src[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new_env[j] = NULL;
|
|
||||||
return new_env;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **build_qemu_argv(const char *pathname, char *const argv[]) {
|
|
||||||
int argc = 0;
|
|
||||||
while (argv && argv[argc]) argc++;
|
|
||||||
char **new_argv = (char **)malloc((argc + 4) * sizeof(char *));
|
|
||||||
if (!new_argv) return NULL;
|
|
||||||
new_argv[0] = "/usr/bin/qemu-x86_64-static";
|
|
||||||
new_argv[1] = "-L";
|
|
||||||
new_argv[2] = "/usr/x86_64-linux-gnu";
|
|
||||||
new_argv[3] = (char *)pathname;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
new_argv[i + 3] = argv[i];
|
|
||||||
}
|
|
||||||
new_argv[argc + 3] = NULL;
|
|
||||||
return new_argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
int execve(const char *pathname, char *const argv[], char *const envp[]) {
|
|
||||||
static int (*real_execve)(const char *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_execve) real_execve = (int (*)(const char *, char *const [], char *const []))dlsym(RTLD_NEXT, "execve");
|
|
||||||
if (pathname && is_x86_64_elf(pathname)) {
|
|
||||||
char **new_argv = build_qemu_argv(pathname, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
char **clean_envp = clean_env(envp);
|
|
||||||
return real_execve("/usr/bin/qemu-x86_64-static", new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_execve(pathname, argv, envp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int execv(const char *pathname, char *const argv[]) {
|
|
||||||
static int (*real_execv)(const char *, char *const []) = NULL;
|
|
||||||
if (!real_execv) real_execv = (int (*)(const char *, char *const []))dlsym(RTLD_NEXT, "execv");
|
|
||||||
if (pathname && is_x86_64_elf(pathname)) {
|
|
||||||
char **new_argv = build_qemu_argv(pathname, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
extern char **environ;
|
|
||||||
char **clean_envp = clean_env(environ);
|
|
||||||
static int (*real_execve_local)(const char *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_execve_local) real_execve_local = (int (*)(const char *, char *const [], char *const []))dlsym(RTLD_NEXT, "execve");
|
|
||||||
return real_execve_local("/usr/bin/qemu-x86_64-static", new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_execv(pathname, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int execvp(const char *file, char *const argv[]) {
|
|
||||||
static int (*real_execvp)(const char *, char *const []) = NULL;
|
|
||||||
if (!real_execvp) real_execvp = (int (*)(const char *, char *const []))dlsym(RTLD_NEXT, "execvp");
|
|
||||||
if (file && is_x86_64_elf(file)) {
|
|
||||||
char **new_argv = build_qemu_argv(file, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
extern char **environ;
|
|
||||||
char **clean_envp = clean_env(environ);
|
|
||||||
static int (*real_execve_local)(const char *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_execve_local) real_execve_local = (int (*)(const char *, char *const [], char *const []))dlsym(RTLD_NEXT, "execve");
|
|
||||||
return real_execve_local("/usr/bin/qemu-x86_64-static", new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_execvp(file, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int execvpe(const char *file, char *const argv[], char *const envp[]) {
|
|
||||||
static int (*real_execvpe)(const char *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_execvpe) real_execvpe = (int (*)(const char *, char *const [], char *const []))dlsym(RTLD_NEXT, "execvpe");
|
|
||||||
if (file && is_x86_64_elf(file)) {
|
|
||||||
char **new_argv = build_qemu_argv(file, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
char **clean_envp = clean_env(envp);
|
|
||||||
static int (*real_execve_local)(const char *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_execve_local) real_execve_local = (int (*)(const char *, char *const [], char *const []))dlsym(RTLD_NEXT, "execve");
|
|
||||||
return real_execve_local("/usr/bin/qemu-x86_64-static", new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_execvpe(file, argv, envp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int posix_spawn(pid_t *pid, const char *path,
|
|
||||||
const posix_spawn_file_actions_t *file_actions,
|
|
||||||
const posix_spawnattr_t *attrp,
|
|
||||||
char *const argv[], char *const envp[]) {
|
|
||||||
static int (*real_posix_spawn)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_posix_spawn) {
|
|
||||||
real_posix_spawn = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []))dlsym(RTLD_NEXT, "posix_spawn");
|
|
||||||
}
|
|
||||||
if (path && is_x86_64_elf(path)) {
|
|
||||||
char **new_argv = build_qemu_argv(path, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
char **clean_envp = clean_env(envp);
|
|
||||||
return real_posix_spawn(pid, "/usr/bin/qemu-x86_64-static", file_actions, attrp, new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_posix_spawn(pid, path, file_actions, attrp, argv, envp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int posix_spawnp(pid_t *pid, const char *file,
|
|
||||||
const posix_spawn_file_actions_t *file_actions,
|
|
||||||
const posix_spawnattr_t *attrp,
|
|
||||||
char *const argv[], char *const envp[]) {
|
|
||||||
static int (*real_posix_spawnp)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_posix_spawnp) {
|
|
||||||
real_posix_spawnp = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []))dlsym(RTLD_NEXT, "posix_spawnp");
|
|
||||||
}
|
|
||||||
if (file && is_x86_64_elf(file)) {
|
|
||||||
char **new_argv = build_qemu_argv(file, argv);
|
|
||||||
if (new_argv) {
|
|
||||||
char **clean_envp = clean_env(envp);
|
|
||||||
static int (*real_posix_spawn_local)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []) = NULL;
|
|
||||||
if (!real_posix_spawn_local) {
|
|
||||||
real_posix_spawn_local = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *,
|
|
||||||
const posix_spawnattr_t *, char *const [], char *const []))dlsym(RTLD_NEXT, "posix_spawn");
|
|
||||||
}
|
|
||||||
return real_posix_spawn_local(pid, "/usr/bin/qemu-x86_64-static", file_actions, attrp, new_argv, clean_envp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return real_posix_spawnp(pid, file, file_actions, attrp, argv, envp);
|
|
||||||
}
|
|
||||||
+2
-7
@@ -12,13 +12,8 @@ service firebase.storage {
|
|||||||
&& request.resource.size < 10 * 1024 * 1024
|
&& request.resource.size < 10 * 1024 * 1024
|
||||||
&& request.resource.contentType.matches('image/.*');
|
&& request.resource.contentType.matches('image/.*');
|
||||||
|
|
||||||
// Löschen streng gesichert: Nur der eigene Verfasser ODER ein Admin aus der Admins-Sammlung
|
// Nur der Verfasser (oder berechtigte Nutzer) darf sein Foto löschen
|
||||||
allow delete: if request.auth != null && (
|
allow delete: if request.auth != null && request.auth.uid == userId;
|
||||||
request.auth.uid == userId ||
|
|
||||||
request.auth.token.admin == true ||
|
|
||||||
firestore.exists(/databases/(default)/documents/Admins/$(request.auth.uid)) ||
|
|
||||||
(request.auth.token.email != null && firestore.exists(/databases/(default)/documents/Admins/$(request.auth.token.email)))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,130 +41,5 @@ void main() {
|
|||||||
expect(map['category'], 'Müll / Verunreinigung');
|
expect(map['category'], 'Müll / Verunreinigung');
|
||||||
expect(map['status'], 'In Bearbeitung');
|
expect(map['status'], 'In Bearbeitung');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parses WordPress JSON accurately with HTML unescape and PDF extraction', () {
|
|
||||||
final wpJson = {
|
|
||||||
'id': 659,
|
|
||||||
'date': '2026-09-10T10:42:00',
|
|
||||||
'title': {'rendered': 'Aussendung 17 – Konzept & Camping'},
|
|
||||||
'content': {
|
|
||||||
'rendered':
|
|
||||||
'<h2 class="wp-block-heading">Aussendung 17</h2><div class="wp-block-file"><object data="https://buergerforumoggau.at/wp-content/uploads/2026/09/20260917_Aussendung_17_-_Camping_Final.pdf" type="application/pdf"></object><a href="https://buergerforumoggau.at/wp-content/uploads/2026/09/20260917_Aussendung_17_-_Camping_Final.pdf">Download</a></div>'
|
|
||||||
},
|
|
||||||
'link': 'https://buergerforumoggau.at/2026/09/aussendung-17/',
|
|
||||||
};
|
|
||||||
|
|
||||||
final item = PostItem.fromWordPressJson(wpJson);
|
|
||||||
expect(item.id, 'wp_659');
|
|
||||||
expect(item.title, 'Aussendung 17 – Konzept & Camping');
|
|
||||||
expect(item.isAussendung, true);
|
|
||||||
expect(item.pdfUrl,
|
|
||||||
'https://buergerforumoggau.at/wp-content/uploads/2026/09/20260917_Aussendung_17_-_Camping_Final.pdf');
|
|
||||||
expect(item.webUrl, 'https://buergerforumoggau.at/2026/09/aussendung-17/');
|
|
||||||
expect(item.category, 'Aussendung');
|
|
||||||
expect(item.createdDate, DateTime.parse('2026-09-10T10:42:00'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('serializes to and from local JSON cache correctly', () {
|
|
||||||
final item = PostItem(
|
|
||||||
id: 'wp_999',
|
|
||||||
title: 'Aussendung 99',
|
|
||||||
description: 'Test Aussendung',
|
|
||||||
createdDate: DateTime(2026, 9, 14, 12, 0),
|
|
||||||
pdfUrl: 'https://buergerforumoggau.at/test.pdf',
|
|
||||||
webUrl: 'https://buergerforumoggau.at/test/',
|
|
||||||
isAussendung: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
final json = item.toJson();
|
|
||||||
final restored = PostItem.fromJson(json);
|
|
||||||
|
|
||||||
expect(restored.id, item.id);
|
|
||||||
expect(restored.title, item.title);
|
|
||||||
expect(restored.pdfUrl, item.pdfUrl);
|
|
||||||
expect(restored.webUrl, item.webUrl);
|
|
||||||
expect(restored.isAussendung, true);
|
|
||||||
expect(restored.createdDate, item.createdDate);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('sorts mixed list of Firestore news and Aussendungen chronologically', () {
|
|
||||||
final oldNews = PostItem(
|
|
||||||
id: 'news_1',
|
|
||||||
title: 'Ältere News',
|
|
||||||
description: 'Text',
|
|
||||||
createdDate: DateTime(2026, 8, 1),
|
|
||||||
);
|
|
||||||
final newAussendung = PostItem(
|
|
||||||
id: 'wp_659',
|
|
||||||
title: 'Aussendung 17',
|
|
||||||
description: 'Text',
|
|
||||||
createdDate: DateTime(2026, 9, 10),
|
|
||||||
isAussendung: true,
|
|
||||||
);
|
|
||||||
final newestNews = PostItem(
|
|
||||||
id: 'news_2',
|
|
||||||
title: 'Neueste Nachricht',
|
|
||||||
description: 'Text',
|
|
||||||
createdDate: DateTime(2026, 9, 14),
|
|
||||||
);
|
|
||||||
|
|
||||||
final list = [oldNews, newAussendung, newestNews];
|
|
||||||
list.sort((a, b) => b.createdDate.compareTo(a.createdDate));
|
|
||||||
|
|
||||||
expect(list[0].id, 'news_2');
|
|
||||||
expect(list[1].id, 'wp_659');
|
|
||||||
expect(list[2].id, 'news_1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('Contact Message & Admin Management Tests', () {
|
|
||||||
test('validates contact message status states and defaults', () {
|
|
||||||
const allowedStatuses = ['Neu', 'In Bearbeitung', 'Erledigt'];
|
|
||||||
expect(allowedStatuses.contains('Neu'), isTrue);
|
|
||||||
expect(allowedStatuses.contains('In Bearbeitung'), isTrue);
|
|
||||||
expect(allowedStatuses.contains('Erledigt'), isTrue);
|
|
||||||
expect(allowedStatuses.contains('Unbekannt'), isFalse);
|
|
||||||
|
|
||||||
const messageMap = {
|
|
||||||
'subject': 'Straßenbeleuchtung kaputt',
|
|
||||||
'message': 'Vor der Schule ist es dunkel.',
|
|
||||||
'senderName': 'Max Mustermann',
|
|
||||||
'senderEmail': 'max@example.com',
|
|
||||||
'senderPhone': '0664 1234567',
|
|
||||||
'status': 'Neu',
|
|
||||||
'userId': 'user-123',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(messageMap['status'], 'Neu');
|
|
||||||
expect(messageMap['senderEmail'], 'max@example.com');
|
|
||||||
expect(messageMap['userId'], 'user-123');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('validates user profile normalization and admin lookup', () {
|
|
||||||
String normalizeEmail(String email) => email.trim().toLowerCase();
|
|
||||||
|
|
||||||
const rawEmail = ' Admin.Test@Oggau.at ';
|
|
||||||
expect(normalizeEmail(rawEmail), 'admin.test@oggau.at');
|
|
||||||
|
|
||||||
const adminUids = {'uid_123', 'uid_456'};
|
|
||||||
const adminEmails = {'admin.test@oggau.at', 'buergermeister@oggau.at'};
|
|
||||||
|
|
||||||
bool isUserAdmin(String uid, String email) {
|
|
||||||
return adminUids.contains(uid) || adminEmails.contains(normalizeEmail(email));
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(isUserAdmin('uid_123', 'other@mail.com'), isTrue);
|
|
||||||
expect(isUserAdmin('uid_999', 'Admin.Test@oggau.at'), isTrue);
|
|
||||||
expect(isUserAdmin('uid_999', 'regular.user@oggau.at'), isFalse);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('prevents self-demotion check logic', () {
|
|
||||||
bool canDemote(String targetUid, String currentUid) {
|
|
||||||
return targetUid != currentUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(canDemote('target_user', 'current_admin'), isTrue);
|
|
||||||
expect(canDemote('current_admin', 'current_admin'), isFalse);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user