Browse Source

fix error

git@h5.yoqi.me 1 year ago
parent
commit
1c390dc108
7 changed files with 88 additions and 29 deletions
  1. 0 1
      lib/main.dart
  2. 1 1
      lib/pages/home_page.dart
  3. 8 6
      lib/utils/sp_utils.dart
  4. 3 3
      lib/views/record_list.dart
  5. 4 4
      lib/views/recorder.dart
  6. 70 14
      pubspec.lock
  7. 2 0
      pubspec.yaml

+ 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(

+ 8 - 6
lib/utils/sp_utils.dart

@@ -1,17 +1,20 @@
 import 'package:shared_preferences/shared_preferences.dart';
 
 class SpUtil {
-  static Future<SharedPreferences> sharedPreferences = SharedPreferences.getInstance();
+  static Future<SharedPreferences> sharedPreferences =
+      SharedPreferences.getInstance();
 
-  static Future<T> get<T>(String key) {
-    key ??= '';
+  static Future<T> get<T>(String key, T defaultValue) {
     return sharedPreferences.then((s) {
-      return s.get(key) as T;
+      if (s.get(key) == null) {
+        return defaultValue;
+      } else {
+        return s.get(key) as T;
+      }
     });
   }
 
   static Future<bool> save<T>(String key, T value) async {
-    key ??= '';
     return sharedPreferences.then((s) {
       if (value == null) {
         return s.remove(key);
@@ -37,7 +40,6 @@ class SpUtil {
   }
 
   static Future<bool> remove(String key) {
-    key ??= '';
     return sharedPreferences.then((s) {
       return s.remove(key);
     });

+ 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,

+ 70 - 14
pubspec.lock

@@ -49,7 +49,7 @@ packages:
       name: collection
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.16.0"
+    version: "1.15.0"
   crypto:
     dependency: transitive
     description:
@@ -70,7 +70,7 @@ packages:
       name: fake_async
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.3.0"
+    version: "1.2.0"
   ffi:
     dependency: transitive
     description:
@@ -120,7 +120,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:
@@ -134,7 +134,7 @@ packages:
       name: js
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.6.4"
+    version: "0.6.3"
   lints:
     dependency: transitive
     description:
@@ -155,7 +155,7 @@ packages:
       name: material_color_utilities
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.1.4"
+    version: "0.1.3"
   meta:
     dependency: transitive
     description:
@@ -169,14 +169,14 @@ packages:
       name: mime
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.0.1"
+    version: "1.0.2"
   path:
     dependency: transitive
     description:
       name: path
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.8.1"
+    version: "1.8.0"
   path_provider:
     dependency: "direct main"
     description:
@@ -190,14 +190,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:
@@ -268,6 +268,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
@@ -279,7 +335,7 @@ packages:
       name: source_span
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.8.2"
+    version: "1.8.1"
   stack_trace:
     dependency: transitive
     description:
@@ -314,14 +370,14 @@ packages:
       name: test_api
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "0.4.9"
+    version: "0.4.8"
   typed_data:
     dependency: transitive
     description:
       name: typed_data
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "1.3.1"
+    version: "1.3.0"
   uuid:
     dependency: transitive
     description:
@@ -335,7 +391,7 @@ packages:
       name: vector_math
       url: "https://pub.flutter-io.cn"
     source: hosted
-    version: "2.1.2"
+    version: "2.1.1"
   win32:
     dependency: transitive
     description:
@@ -351,5 +407,5 @@ packages:
     source: hosted
     version: "0.2.0+1"
 sdks:
-  dart: ">=2.16.0-100.0.dev <3.0.0"
+  dart: ">=2.15.0 <3.0.0"
   flutter: ">=2.8.1"

+ 2 - 0
pubspec.yaml

@@ -17,6 +17,8 @@ dependencies:
 
 #  rflutter_alert: ^2.0.2
   share: ^2.0.4
+  shared_preferences: ^2.0.7
+
 
 dev_dependencies:
   flutter_test: