构建发布后 Flutter 应用卡在白屏上

时间:2021-05-25 14:09:31

标签: android ios flutter

在我的 iPhone 7 中构建发布版本的应用程序后,这是我看到的屏幕: enter image description here

它应该是这样的: enter image description here

这在 Android 和 iOS 的发布模式中是一样的。当我在模拟器(调试模式)上运行应用程序时,应用程序工作正常。该应用使用 HTTPS 请求来工作,这可能是问题所在吗?

我的 Info.plist 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>View MET</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
</dict>
</plist>

我在 /main 中的 AndroidManifest.xml 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emirs.view_met">
    <uses-permission android:name="android.permission.INTERNET" />
   <application
        android:label="View MET"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

我的 Flutter 版本:

Flutter 2.3.0-13.0.pre.145 • channel master • https://github.com/flutter/flutter.git
Framework • revision fdb1fb184d (9 hours ago) • 2021-05-24 22:04:02 -0700
Engine • revision b1385c0df1
Tools • Dart 2.14.0 (build 2.14.0-145.0.dev)

我的家.dart:

import 'dart:convert';
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
import 'package:view_met/search.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'about.dart';
import 'all.dart';
import 'detailsArt.dart';
import 'favorites.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  void initState() {
    super.initState();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
  }

  checkEmpty() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var list = prefs.getStringList("favorites");

    if (list == null) {
      prefs.setStringList("favorites", []);
    }
  }


  fetchData(String id) async {
    var request = await http.get(Uri.parse("https://collectionapi.metmuseum.org/public/collection/v1/objects/$id"));

    return request.body;
  }

  _writeData(String id) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var list = prefs.getStringList("favorites");

    if (list!.contains(id)) {
      ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text("This item is already in your favorites!"),
          )
      );
    }
    else {
      list.add(id);

      prefs.setStringList("favorites", list);

      ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text("Added to your favorites list"),
            action: SnackBarAction(
              label: 'Undo',
              onPressed: () {
                _deleteData(id);
              },
            ),
          )
      );
    }
  }

  _deleteData(String id) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var list = prefs.getStringList("favorites");

    list!.remove(id);

    prefs.setStringList("favorites", list);

    ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text("Removed from your favorites list"),
          action: SnackBarAction(
            label: 'Undo',
            onPressed: () {
              _writeData(id);
            },
          ),
        )
    );
  }

  @override
  Widget build(BuildContext context) {

    checkEmpty();

    welcomeText() {
      var now = DateTime.now();

      if (now.hour <= 11 && now.hour >= 5) {
        return Text("Good Morning", style: GoogleFonts.playfairDisplaySc(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold));
      }
      else if (now.hour <= 17 && now.hour >= 12) {
        return Text("Good Afternoon", style: GoogleFonts.playfairDisplaySc(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),);
      }
      else if (now.hour <= 21 && now.hour >= 18 && now.hour >= 19 && now.hour >= 5 || now.hour == 0) {
        return Text("Good Evening", style: GoogleFonts.playfairDisplaySc(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),);
      }
      else {
        return Text("Hello", style: GoogleFonts.playfairDisplaySc(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),);
      }
    }

    var randint1 = Random().nextInt(70000);
    var randint2 = Random().nextInt(70000);
    var randint3 = Random().nextInt(70000);
    var randint4 = Random().nextInt(70000);
    var randint5 = Random().nextInt(70000);
    var randint6 = Random().nextInt(70000);


    builder(String id) {
      return FutureBuilder(
        future: fetchData(id),
        builder: (BuildContext context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Padding(
              padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
              child: CircularProgressIndicator(),
            );
          }
          var data = jsonDecode(snapshot.data.toString());

          var leading;
          var artist;

          try {
            if (data["primaryImageSmall"] == "") {
              leading = Icon(Icons.dangerous, color: Colors.red);
            }
            else {
              leading = Image.network(data["primaryImageSmall"]);
            }

            if (data["artistDisplayName"]== "") {
              artist = "Unknown";
            }
            else {
              artist = data["artistDisplayName"];
            }
          }
          on TypeError {
            return SizedBox.shrink();
          }

          return Card(
            clipBehavior: Clip.antiAlias,
            child: Column(
              children: [
                ListTile(
                  leading: leading,
                  title: Text(data["title"]),
                  subtitle: Text(
                    "by $artist",
                    style: TextStyle(color: Colors.black.withOpacity(0.6)),
                  ),
                ),
                ButtonBar(
                  alignment: MainAxisAlignment.start,
                  children: [
                    TextButton(
                      onPressed: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => DetailsPage(id: data["objectID"].toString())),
                        );
                      },
                      child: Text("Details", style: TextStyle(color: Colors.red)),
                    ),
                    TextButton(
                      onPressed: () {
                        _writeData(data["objectID"].toString());
                      },
                      child: Text("Add to Favorites", style: TextStyle(color: Colors.red)),
                    ),
                  ],
                ),
              ],
            ),
          );
        },
      );
    }

    var _controller = TextEditingController();


    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Center(
        child: Column(
          children: <Widget>[
            Stack(
              children: <Widget>[
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: 400,
                  child: Positioned.fill(
                    child: Image.asset(
                        "assets/MET.jpg",
                        fit: BoxFit.fill,
                        color: Color.fromRGBO(117, 117, 117, 0.5),
                        colorBlendMode: BlendMode.modulate
                    ),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 50, 0, 20),
                  child: Align(
                    alignment: Alignment.topRight,
                    child: IconButton(
                      iconSize: 30,
                      color: Colors.white,
                      icon: Icon(Icons.info),
                      onPressed: () {
                        Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => AboutPage()),
                        );
                      },
                    ),
                  )
                ),
                Padding(
                    padding: EdgeInsets.fromLTRB(0, 50, 40, 20),
                    child: Align(
                      alignment: Alignment.topRight,
                      child: IconButton(
                        iconSize: 30,
                        color: Colors.white,
                        icon: Icon(Icons.favorite),
                        onPressed: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) => FavoritesPage()),
                          );
                        },
                      ),
                    )
                ),
                Padding(
                    padding: EdgeInsets.fromLTRB(0, 50,80, 20),
                    child: Align(
                      alignment: Alignment.topRight,
                      child: IconButton(
                        iconSize: 30,
                        color: Colors.white,
                        icon: Icon(Icons.refresh_outlined),
                        onPressed: () {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (BuildContext context) => this.widget)
                          );
                        },
                      ),
                    )
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 150, 0, 20),
                  child: Align(
                    alignment: Alignment.bottomCenter,
                    child: Text(
                      'View MET',
                      style: GoogleFonts.playfairDisplaySc(fontSize: 40, color: Colors.white, fontWeight: FontWeight.bold),
                    ),
                  )
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 200, 0, 20),
                  child: Align(
                    alignment: Alignment.bottomCenter,
                    child: welcomeText(),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 280, 0, 20),
                  child: Align(
                    alignment: Alignment.bottomCenter,
                    child: Container(
                      width: 300,
                      child: TextField(
                        controller: _controller,
                        onSubmitted: (String value) {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (BuildContext context) => SearchPage(text: _controller.text)
                              )
                          );
                        },
                        decoration: InputDecoration(
                            prefixIcon: Icon(Icons.search),
                            border: OutlineInputBorder(
                              borderRadius: BorderRadius.all(
                                Radius.circular(99),
                              ),
                            ),
                            filled: true,
                            hintStyle: TextStyle(color: Colors.black),
                            hintText: "Search View MET",
                            fillColor: Colors.white
                        ),
                      ),
                    )
                  ),
                ),
              ]
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(0, 20, 0, 0),
              child: Column(
                children: <Widget>[
                  Text("Random Items You Could Like", style: GoogleFonts.merriweather(fontSize: 18, color: Colors.black)),
                  SizedBox(
                    height: MediaQuery.of(context).size.height - 443,
                    child: Expanded(
                      child: SingleChildScrollView(
                        scrollDirection: Axis.vertical,
                        child: Column(
                          children: <Widget>[
                            builder(randint1.toString()),
                            builder(randint2.toString()),
                            builder(randint3.toString()),
                            builder(randint4.toString()),
                            builder(randint5.toString()),
                            builder(randint6.toString()),
                            TextButton(
                             onPressed: () {
                               Navigator.push(
                                   context,
                                   MaterialPageRoute(
                                       builder: (BuildContext context) => AllPage()
                                   )
                               );
                             },
                             child: Text("See more"),
                            )
                          ],
                        )
                      ),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

我认为 HTTPS 请求是冻结应用程序的原因。我查了一些其他问题,但没有一个真正奏效。

0 个答案:

没有答案
相关问题