#2 优化代码

Merged
lyq merged 4 commits from lyq/hotfix/gray-snipe into lyq/master 1 year ago

+ 1 - 0
.devcontainer/Dockerfile

@@ -0,0 +1 @@
+FROM jianboy/flutter-dev-container:3.0.5

+ 45 - 0
.devcontainer/devcontainer.json

@@ -0,0 +1,45 @@
+// java8 + android env
+// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
+// https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/java-8
+{
+    "name": "Java 11",
+    "build": {
+        "dockerfile": "Dockerfile",
+        "args": {
+            // Use the VARIANT arg to pick a Debian OS version: buster, bullseye
+            // Use bullseye when running on local arm64/Apple Silicon.
+            "VARIANT": "buster",
+            // Options
+            "INSTALL_MAVEN": "true",
+            "INSTALL_GRADLE": "true",
+            "NODE_VERSION": "lts/*"
+        }
+    },
+    // Set *default* container specific settings.json values on container create.
+    "settings": {
+        "java.home": "/docker-java-home",
+        "java.import.gradle.java.home": "/usr/local/sdkman/candidates/java/current",
+        "java.configuration.runtimes": [
+            {
+                "default": true,
+                "name": "JavaSE-11",
+                "path": "/usr/local/sdkman/candidates/java/current"
+            }
+        ]
+    },
+    // Add the IDs of extensions you want installed when the container is created.
+    "extensions": [
+        "vscjava.vscode-java-pack",
+        "dart-code.dart-code",
+        "dart-code.flutter"
+    ],
+    // Use 'forwardPorts' to make a list of ports inside the container available locally.
+    // "forwardPorts": [],
+    // Use 'postCreateCommand' to run commands after the container is created.
+    // "postCreateCommand": "java -version",
+    // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
+    "remoteUser": "vscode",
+    "features": {
+        "docker-in-docker": "latest"
+    }
+}

+ 66 - 0
.gitpod.Dockerfile

@@ -0,0 +1,66 @@
+FROM gitpod/workspace-full-vnc
+SHELL ["/bin/bash", "-c"]
+
+ENV ANDROID_HOME=/home/gitpod/androidsdk \
+    FLUTTER_VERSION=2.10.5-stable
+
+# Install dart
+USER root
+RUN curl -fsSL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
+    && curl -fsSL https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list \
+    && install-packages build-essential dart libkrb5-dev gcc make gradle android-tools-adb android-tools-fastboot
+
+# Install flutter
+USER gitpod
+RUN cd /home/gitpod \
+    && wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}.tar.xz \
+    && tar -xvf flutter*.tar.xz \
+    && rm -f flutter*.tar.xz
+
+RUN flutter/bin/flutter precache
+RUN echo 'export PATH="$PATH:/home/gitpod/flutter/bin"' >> /home/gitpod/.bashrc
+
+# Install Open JDK
+USER gitpod
+RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \
+    sdk install java 11.0.16-amzn && \
+    sdk default java 11.0.16-amzn"
+
+# Install SDK Manager
+USER gitpod
+RUN  wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip \
+    && mkdir -p $ANDROID_HOME/cmdline-tools/latest \
+    && unzip commandlinetools-linux-*.zip -d $ANDROID_HOME \
+    && rm -f commandlinetools-linux-*.zip \
+    && mv $ANDROID_HOME/cmdline-tools/bin $ANDROID_HOME/cmdline-tools/latest \
+    && mv $ANDROID_HOME/cmdline-tools/lib $ANDROID_HOME/cmdline-tools/latest
+
+RUN echo "export ANDROID_HOME=$ANDROID_HOME" >> /home/gitpod/.bashrc \
+    && echo 'export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/bin:$ANDROID_HOME/platform-tools:$PATH' >> /home/gitpod/.bashrc
+
+# Install Android Image version 30
+USER gitpod
+RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-30" "emulator"
+RUN yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-30;google_apis;x86_64"
+RUN echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n avd28 -k "system-images;android-30;google_apis;x86_64"
+
+
+# Install Google Chrome
+USER root
+RUN apt-get update \
+  && apt-get install -y apt-transport-https \
+  && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
+  && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
+  && apt-get update \
+  && sudo apt-get install -y google-chrome-stable
+
+# misc deps
+RUN apt-get install -y \
+  libasound2-dev \
+  libgtk-3-dev \
+  libnss3-dev \
+  fonts-noto \
+  fonts-noto-cjk
+
+# For Qt WebEngine on docker
+ENV QTWEBENGINE_DISABLE_SANDBOX 1

+ 75 - 0
.gitpod.yml

@@ -0,0 +1,75 @@
+image:
+  file: .gitpod.Dockerfile
+tasks:
+  - before: sudo mount -t tmpfs shm -osize=4096m /dev/shm
+  - init: |
+      flutter channel beta
+      flutter upgrade
+
+      # flutter config --enable-web
+      flutter config --android-sdk /home/gitpod/androidsdk
+      yes | flutter doctor --android-licenses
+
+      # flutter doctor
+
+      # flutter pub get
+
+      # flutter build -v bundle
+      # flutter build -v web
+      # flutter build -v appbundle
+      # flutter build -v apk
+      
+  # - command: |
+  #     # Gitpod is not able to run emulators within a worspace at this stage as
+  #     # Google Kubernetes Engine does not support Nested Virtualization.
+  #     #
+  #     # If running Gitpod on your own infrastructure or via the Dockerfile locally
+  #     # on infrastructure that exposes vmx or svm then this command will launch
+  #     # the emulator.
+  #     #
+  #     # $ emulator -avd avd28 -no-audio -no-window 
+  #     #
+  #     # Until this restriction is mitigated you can run native mobile apps in your
+  #     # browser via https://appetize.io/
+
+  #     if [[ -z "$APPETIZE_API_TOKEN" ]]; then
+  #         echo "Appetize API token not set. Run:"
+  #         echo ""
+  #         echo "    gp env APPETIZE_API_TOKEN=your_token"
+  #         echo ""
+  #         echo "and restart this workspace in order to get an app preview."
+  #         echo ""
+  #         echo "Request your token here: https://appetize.io/docs#request-api-token"
+  #     else
+  #         curl -sS --http1.1 "https://$APPETIZE_API_TOKEN@api.appetize.io/v1/apps/$APPETIZE_PUBLICKEY" \
+  #             -F "file=@/workspace/template-flutter/build/app/outputs/flutter-apk/app.apk" \
+  #             -F platform=android \
+  #             -F "buttonText=Start App" \
+  #             -F "postSessionButtonText=Start App" \
+  #             > .appetize.json
+
+  #         APPETIZE_PUBLICKEY=$(jq -r .publicKey .appetize.json)
+  #         gp env "APPETIZE_PUBLICKEY=$APPETIZE_PUBLICKEY"
+  #         export APPETIZE_PUBLICKEY
+
+  #         python -m webbrowser "https://appetize.io/embed/$APPETIZE_PUBLICKEY?device=pixel4&autoplay=true"
+  #     fi
+
+  #     flutter devices
+    
+  #     flutter run --web-port 8080
+
+
+ports:
+  - port: 5900
+    onOpen: ignore
+    # vnc
+  - port: 6080
+    onOpen: open-preview
+    # flutter
+  - port: 8080
+    onOpen: open-preview
+
+vscode:
+  extensions:
+    - dart-code.flutter

+ 1 - 1
android/build.gradle

@@ -7,7 +7,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:4.1.0'
+        classpath 'com.android.tools.build:gradle:7.2.2'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
     }
 }

+ 1 - 1
android/gradle/wrapper/gradle-wrapper.properties

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

+ 0 - 1
lib/main.dart

@@ -16,7 +16,6 @@ class MyApp extends StatelessWidget {
       theme: ThemeData(
         primarySwatch: Colors.blue,
         visualDensity: VisualDensity.adaptivePlatformDensity,
-
       ),
       home: const HomePage(),
     );

+ 1 - 1
lib/pages/home_page.dart

@@ -37,7 +37,7 @@ class _HomePageState extends State<HomePage> {
       ),
       body: Stack(
         children: [
-          Center(child: Text("天问科技")),
+          const Center(child: Text("天问科技")),
           Column(
             children: [
               Expanded(

+ 53 - 0
lib/utils/sp_utils.dart

@@ -0,0 +1,53 @@
+import 'package:shared_preferences/shared_preferences.dart';
+
+class SpUtil {
+  static Future<SharedPreferences> sharedPreferences =
+      SharedPreferences.getInstance();
+
+  static Future<T> get<T>(String key, T defaultValue) {
+    return sharedPreferences.then((s) {
+      if (s.get(key) == null) {
+        return defaultValue;
+      } else {
+        return s.get(key) as T;
+      }
+    });
+  }
+
+  static Future<bool> save<T>(String key, T value) async {
+    return sharedPreferences.then((s) {
+      if (value == null) {
+        return s.remove(key);
+      } else {
+        if (value is int) {
+          return s.setInt(key, value);
+        }
+        if (value is double) {
+          return s.setDouble(key, value);
+        }
+        if (value is String) {
+          return s.setString(key, value);
+        }
+        if (value is List<String>) {
+          return s.setStringList(key, value);
+        }
+        if (value is bool) {
+          return s.setBool(key, value);
+        }
+      }
+      return false;
+    });
+  }
+
+  static Future<bool> remove(String key) {
+    return sharedPreferences.then((s) {
+      return s.remove(key);
+    });
+  }
+
+  static Future<bool> clear() {
+    return sharedPreferences.then((s) {
+      return s.clear();
+    });
+  }
+}

+ 3 - 3
lib/views/record_list.dart

@@ -38,11 +38,11 @@ class _RecordListState extends State<RecordList> {
           child: ExpansionTile(
             title: Text(
               'Record ${widget.records.length - i}',
-              style: TextStyle(color: Colors.black),
+              style: const TextStyle(color: Colors.black),
             ),
             subtitle: Text(
               _getTime(filePath: widget.records.elementAt(i)),
-              style: TextStyle(color: Colors.black38),
+              style: const TextStyle(color: Colors.black38),
             ),
             onExpansionChanged: ((newState) {
               if (newState) {
@@ -61,7 +61,7 @@ class _RecordListState extends State<RecordList> {
                     LinearProgressIndicator(
                       minHeight: 5,
                       backgroundColor: Colors.black,
-                      valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
+                      valueColor: const AlwaysStoppedAnimation<Color>(Colors.green),
                       value: _selected == i ? _percent : 0,
                     ),
                     Row(

+ 4 - 4
lib/views/recorder.dart

@@ -133,7 +133,7 @@ class _RecorderViewState extends State<RecorderView> {
                             await _onRecordButtonPressed();
                             setState(() {});
                           },
-                          child: Container(
+                          child: SizedBox(
                             width: 80,
                             height: 80,
                             child: Icon(
@@ -150,16 +150,16 @@ class _RecorderViewState extends State<RecorderView> {
                                   borderRadius: BorderRadius.circular(10),
                                 ),
                               ),
-                              textStyle: MaterialStateProperty.all(TextStyle(
+                              textStyle: MaterialStateProperty.all(const TextStyle(
                                 color: Colors.orange,
                               ))),
                           onPressed: _currentStatus != RecordingStatus.Unset
                               ? _stop
                               : null,
-                          child: Container(
+                          child: const SizedBox(
                             width: 80,
                             height: 80,
-                            child: const Icon(
+                            child: Icon(
                               Icons.stop,
                               color: Colors.white,
                               size: 50,

+ 129 - 10
pubspec.lock

@@ -14,7 +14,49 @@ packages:
       name: audioplayers
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.20.1"
+    version: "1.0.1"
+  audioplayers_android:
+    dependency: transitive
+    description:
+      name: audioplayers_android
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.1"
+  audioplayers_darwin:
+    dependency: transitive
+    description:
+      name: audioplayers_darwin
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.1"
+  audioplayers_linux:
+    dependency: transitive
+    description:
+      name: audioplayers_linux
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.0"
+  audioplayers_platform_interface:
+    dependency: transitive
+    description:
+      name: audioplayers_platform_interface
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.0"
+  audioplayers_web:
+    dependency: transitive
+    description:
+      name: audioplayers_web
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.0"
+  audioplayers_windows:
+    dependency: transitive
+    description:
+      name: audioplayers_windows
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "1.0.0"
   boolean_selector:
     dependency: transitive
     description:
@@ -96,7 +138,7 @@ packages:
       name: flutter_lints
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.4"
+    version: "2.0.1"
   flutter_test:
     dependency: "direct dev"
     description: flutter
@@ -120,7 +162,7 @@ packages:
       name: http
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.13.4"
+    version: "0.13.5"
   http_parser:
     dependency: transitive
     description:
@@ -141,7 +183,7 @@ packages:
       name: lints
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.1"
+    version: "2.0.0"
   matcher:
     dependency: transitive
     description:
@@ -169,7 +211,7 @@ packages:
       name: mime
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.1"
+    version: "1.0.2"
   path:
     dependency: transitive
     description:
@@ -190,14 +232,14 @@ packages:
       name: path_provider_android
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "2.0.14"
+    version: "2.0.17"
   path_provider_ios:
     dependency: transitive
     description:
       name: path_provider_ios
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "2.0.9"
+    version: "2.0.11"
   path_provider_linux:
     dependency: transitive
     description:
@@ -232,7 +274,21 @@ packages:
       name: permission_handler
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "8.3.0"
+    version: "10.0.0"
+  permission_handler_android:
+    dependency: transitive
+    description:
+      name: permission_handler_android
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "10.0.0"
+  permission_handler_apple:
+    dependency: transitive
+    description:
+      name: permission_handler_apple
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "9.0.4"
   permission_handler_platform_interface:
     dependency: transitive
     description:
@@ -240,6 +296,13 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "3.7.0"
+  permission_handler_windows:
+    dependency: transitive
+    description:
+      name: permission_handler_windows
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "0.1.0"
   platform:
     dependency: transitive
     description:
@@ -268,6 +331,62 @@ packages:
       url: "https://pub.flutter-io.cn"
     source: hosted
     version: "2.0.4"
+  shared_preferences:
+    dependency: "direct main"
+    description:
+      name: shared_preferences
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.15"
+  shared_preferences_android:
+    dependency: transitive
+    description:
+      name: shared_preferences_android
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.12"
+  shared_preferences_ios:
+    dependency: transitive
+    description:
+      name: shared_preferences_ios
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.1.1"
+  shared_preferences_linux:
+    dependency: transitive
+    description:
+      name: shared_preferences_linux
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.1.1"
+  shared_preferences_macos:
+    dependency: transitive
+    description:
+      name: shared_preferences_macos
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.4"
+  shared_preferences_platform_interface:
+    dependency: transitive
+    description:
+      name: shared_preferences_platform_interface
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.0"
+  shared_preferences_web:
+    dependency: transitive
+    description:
+      name: shared_preferences_web
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.0.4"
+  shared_preferences_windows:
+    dependency: transitive
+    description:
+      name: shared_preferences_windows
+      url: "https://pub.flutter-io.cn"
+    source: hosted
+    version: "2.1.1"
   sky_engine:
     dependency: transitive
     description: flutter
@@ -321,7 +440,7 @@ packages:
       name: typed_data
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.3.1"
+    version: "1.3.0"
   uuid:
     dependency: transitive
     description:
@@ -351,5 +470,5 @@ packages:
     source: hosted
     version: "0.2.0+1"
 sdks:
-  dart: ">=2.16.0-100.0.dev <3.0.0"
+  dart: ">=2.17.6 <3.0.0"
   flutter: ">=2.8.1"

+ 6 - 4
pubspec.yaml

@@ -4,24 +4,26 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 version: 1.1.0+1
 
 environment:
-  sdk: ">=2.12.0 <3.0.0"
+  sdk: ">=2.17.6 <3.0.0"
 dependencies:
   flutter:
     sdk: flutter
 
   cupertino_icons: ^1.0.3
   fluttertoast: ^8.0.8
-  permission_handler: ^8.1.4+1
+  permission_handler: ^10.0.0
   path_provider: ^2.0.7
-  audioplayers: ^0.20.1
+  audioplayers: ^1.0.1
 
 #  rflutter_alert: ^2.0.2
   share: ^2.0.4
+  shared_preferences: ^2.0.7
+
 
 dev_dependencies:
   flutter_test:
     sdk: flutter
-  flutter_lints: ^1.0.0
+  flutter_lints: ^2.0.1
 
 flutter: