Browse Source

flutter update 3.7

liuyuqi-dellpc 11 months ago
parent
commit
7e7a6f86a0

+ 2 - 2
android/app/build.gradle

@@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
 
 android {
-    compileSdkVersion 31
+    compileSdkVersion 33
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
@@ -36,7 +36,7 @@ android {
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
         applicationId "me.yoqi.flutter.flutter_slider"
         minSdkVersion 16
-        targetSdkVersion 31
+        targetSdkVersion 33
         versionCode flutterVersionCode.toInteger()
         versionName flutterVersionName
     }

+ 1 - 0
android/app/src/main/AndroidManifest.xml

@@ -5,6 +5,7 @@
         android:icon="@mipmap/ic_launcher">
         <activity
             android:name=".MainActivity"
+            android:exported="true"
             android:launchMode="singleTop"
             android:theme="@style/LaunchTheme"
             android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

+ 2 - 2
lib/main.dart

@@ -3,11 +3,11 @@ import 'package:flutter/material.dart';
 import 'pages/home_page.dart';
 
 void main() {
-  runApp(const MyApp());
+  runApp(MyApp());
 }
 
 class MyApp extends StatelessWidget {
-  const MyApp({Key key}) : super(key: key);
+  const MyApp({Key? key}) : super(key: key);
 
   // This widget is the root of your application.
   @override

+ 2 - 2
lib/pages/home_page.dart

@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
 import 'package:flutter_slider/views/custom_banner.dart';
 
 class HomePage extends StatefulWidget {
-  const HomePage({Key key}) : super(key: key);
+  const HomePage({Key? key}) : super(key: key);
 
   @override
   _HomePageState createState() => _HomePageState();
@@ -21,7 +21,7 @@ class _HomePageState extends State<HomePage> {
       appBar: AppBar(
         title: const Text("校内铺子"),
       ),
-      body: CustomBanner(_imgData),
+      body: CustomBanner(_imgData, onTap: (int value) {  },),
     );
   }
 }

+ 12 - 15
lib/views/custom_banner.dart

@@ -8,21 +8,21 @@ class CustomBanner extends StatefulWidget {
   final ValueChanged<int> onTap;
   final Curve curve;
 
-  CustomBanner(
-      this._images, {
-        this.height = 200,
-        this.onTap,
-        this.curve = Curves.linear,
-      }) : assert(_images != null);
+  const CustomBanner(
+    this._images, {super.key,
+    this.height = 200,
+    required this.onTap,
+    this.curve = Curves.linear,
+  }) : assert(_images != null);
 
   @override
   _CustomBannerState createState() => _CustomBannerState();
 }
 
 class _CustomBannerState extends State<CustomBanner> {
-  PageController _pageController;
-  int _curIndex;
-  Timer _timer;
+  late PageController _pageController;
+  late int _curIndex;
+  late Timer _timer;
 
   @override
   void initState() {
@@ -68,7 +68,7 @@ class _CustomBannerState extends State<CustomBanner> {
 
   Widget _buildPageView() {
     var length = widget._images.length;
-    return Container(
+    return SizedBox(
       height: widget.height,
       child: PageView.builder(
         controller: _pageController,
@@ -87,7 +87,7 @@ class _CustomBannerState extends State<CustomBanner> {
               _cancelTimer();
             },
             onTap: () {
-              Scaffold.of(context).showSnackBar(
+              ScaffoldMessenger.of(context).showSnackBar(
                 SnackBar(
                   content: Text('当前 page 为 ${index % length}'),
                   duration: Duration(milliseconds: 500),
@@ -108,15 +108,13 @@ class _CustomBannerState extends State<CustomBanner> {
   _cancelTimer() {
     if (_timer != null) {
       _timer.cancel();
-      _timer = null;
       _initTimer();
     }
   }
 
   /// 初始化定时任务
   _initTimer() {
-    if (_timer == null) {
-      _timer = Timer.periodic(Duration(seconds: 3), (t) {
+    _timer ??= Timer.periodic(Duration(seconds: 3), (t) {
         _curIndex++;
         _pageController.animateToPage(
           _curIndex,
@@ -124,7 +122,6 @@ class _CustomBannerState extends State<CustomBanner> {
           curve: Curves.linear,
         );
       });
-    }
   }
 
   /// 切换页面,并刷新小圆点

+ 1 - 1
test/widget_test.dart

@@ -13,7 +13,7 @@ import 'package:flutter_slider/main.dart';
 void main() {
   testWidgets('Counter increments smoke test', (WidgetTester tester) async {
     // Build our app and trigger a frame.
-    await tester.pumpWidget(const MyApp());
+    await tester.pumpWidget(MyApp());
 
     // Verify that our counter starts at 0.
     expect(find.text('0'), findsOneWidget);