【问题标题】:I am not able to solve the size problem in flutter splash screen我无法解决颤动闪屏中的尺寸问题
【发布时间】:2020-11-02 18:10:54
【问题描述】:

我在启动画面中使用的 GIF 的大小没有全屏显示。

我想在整个屏幕上显示这个 GIT。

请帮助我或建议我如何全屏显示它。

import 'package:flutter/material.dart';
import 'package:moms_kitchen/login_page.dart';
import 'package:splashscreen/splashscreen.dart';


void main() {
  runApp(new MaterialApp(
    debugShowCheckedModeBanner: false,
    home: new MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: SplashScreen(
        seconds: 6,
        backgroundColor: Colors.white,
        image: new Image.asset('assets/splash1.gif'),
        loaderColor: Colors.white,
        photoSize: 250,
        navigateAfterSeconds: MainScreen(),
      ),
    );
  }
}

class MainScreen extends StatefulWidget {
  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Mom's Kitchen",
      theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          fontFamily: 'LeonSans'),
      home: LoginPage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

【问题讨论】:

    标签: android android-studio flutter resize animated-gif


    【解决方案1】:

    从这里

     backgroundColor: Colors.white,
            image: new Image.asset('assets/splash1.gif'),
            loaderColor: Colors.white,
            photoSize: 250,
    

    您将高度设置为 250。

    获取设备屏幕高度可以通过

    var height=MediaQuery.of(context).size.height* 1;
    

    然后使用高度作为您的照片尺寸

    【讨论】:

    • 和宽度?
    • var height=MediaQuery.of(context).size.height* 1;在这个 var 在我的程序中给出错误
    • 宽度:MediaQuery.of(context).size.width,高度:MediaQuery.of(context).size.height,
    【解决方案2】:

    尝试类似的方法可能会有所帮助

    child: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
     
    

    【讨论】:

      【解决方案3】:

      将您的SplashScreen 小部件包装在SafeArea 中。

      通过足够的填充插入其子级的小部件以避免操作系统的入侵。

      例如,这将使子级缩进足以避开屏幕顶部的状态栏。

      然后将您的image 参数包装在带有设备尺寸的Container 中。

      SafeArea(
        child: SplashScreen(
          ...
          image: Container(
            child: Image.asset('assets/splash1.gif'),
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
          ),
        ),
      ),
      

      【讨论】:

      • return SafeArea( child: SplashScreen( seconds: 6, backgroundColor: Colors.white, image: Container( child: Image.asset('assets/splash1.gif'), width: MediaQuery.of( context).size.width, height: MediaQuery.of(context).size.height, ), // loaderColor: Colors.white, //photoSize: 250, navigateAfterSeconds: MainScreen(), ), );那么它也不起作用的错误是'不能将参数类型容器分配给参数类型图像'
      猜你喜欢
      • 2015-08-10
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 2019-11-18
      相关资源
      最近更新 更多