如何在Dart Flutter中设计启动屏幕

huangapple go评论98阅读模式
英文:

How can i design my splash screen in dart flutter

问题

这是我的启动屏幕外观,那么如何使徽标填充圆形形状,以及如何添加背景图像?

英文:

如何在Dart Flutter中设计启动屏幕

This is how my splash screen appears, so how can I make it that the logo is filling up the rounded circle shape, and how can i make it that so I can add a background image

答案1

得分: 1

如果你想根据你写的代码获得反馈,
你必须附上代码的那部分。

或者,如果你可以使用全新的方法,
请使用下面链接中的 flutter_native_splash

https://pub.dev/packages/flutter_native_splash

英文:

If you want feedback based on the code you wrote,
you must attach that part of the code.

Or, if you can apply a completely new method,
use flutter_native_splash in the link below.

https://pub.dev/packages/flutter_native_splash

答案2

得分: 0

你可以使用 flutter_native_splash 插件来完成此操作,或者从头开始手动创建一个完整的启动画面。我在这里提供了一个示例。ClipOval 将使图像完全变为圆形,因为我们需要背景图像,所以我将一切都设置在一个 Stack 小部件中。在 initState 中,我调用了处理导航的导航函数。

  1. navigation() async {
  2. Timer(const Duration(milliseconds: 3000), () {
  3. Navigator.pushReplacement(
  4. context,
  5. MaterialPageRoute(
  6. builder: (context) => MyHomePage(), /// 3 秒后导航到你所需的屏幕
  7. ),
  8. );
  9. });
  10. }
  11. @override
  12. void initState() {
  13. // TODO: implement initState
  14. super.initState();
  15. navigation();
  16. }
  17. @override
  18. Widget build(BuildContext context) {
  19. mq = MediaQuery.of(context).size;
  20. return Scaffold(
  21. body: Container(
  22. height: mq.height, /// 全屏高度
  23. width: mq.width, /// 全屏宽度
  24. child: Stack(
  25. children: [
  26. Align(
  27. alignment: const Alignment(0.0, 0.0),
  28. child: Column(
  29. mainAxisAlignment: MainAxisAlignment.center,
  30. children: [
  31. Container(
  32. height: mq.height,
  33. width: mq.width,
  34. child: Image.asset(
  35. "你的背景图像路径",
  36. ),
  37. ),
  38. ClipOval(
  39. child: Image.asset(
  40. "你的图像路径",
  41. width: "你需要的宽度",
  42. fit: BoxFit.cover,
  43. ),
  44. ),
  45. ],
  46. ),
  47. ),
  48. ],
  49. ),
  50. ),
  51. );
  52. }
英文:

Either you can use flutter_native_splash plugin for this operation or make a splash screen full manually from scratch. I have given an example here. ClipOval will make the image fully rounded and as we need background image I have set everything in a Stack widget. in initState I have called the navigation function which handles the navigation.

  1. navigation() async {
  2. Timer(const Duration(milliseconds: 3000), () {
  3. Navigator.pushReplacement(
  4. context,
  5. MaterialPageRoute(
  6. builder: (context) => MyHomePage(), ///navigate to your
  7. ///desired
  8. ///screen after 3
  9. ///seconds
  10. ),
  11. );
  12. }
  13. )
  14. }
  15. @override
  16. void initState() {
  17. // TODO: implement initState
  18. super.initState();
  19. navigation();
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. mq = MediaQuery.of(context).size;
  24. return Scaffold(
  25. body: Container(
  26. height: mq.height, ///full screen height
  27. width: mq.width, ///full screen width
  28. child: Stack(
  29. children: [
  30. Align(
  31. alignment: const Alignment(0.0, 0.0),
  32. child: Column(
  33. mainAxisAlignment: MainAxisAlignment.center,
  34. children: [
  35. Container(
  36. height: mq.height,
  37. width: mq.width,
  38. child: Image.asset(
  39. "your background image path",
  40. ),
  41. ),
  42. ClipOval(
  43. child: Image.asset(
  44. "Your Image path",
  45. width: "how much you need",
  46. fit: BoxFit.cover,
  47. ),
  48. ),
  49. ],
  50. ),
  51. ),
  52. ],
  53. ),
  54. ),
  55. );
  56. }

答案3

得分: 0

尝试自己编写代码,我会为您提供有关如何构建此类型的启动屏幕的基本想法。

首先,使用 Scaffold 组件。
将 Scaffold 的背景颜色设置为您的启动屏幕的背景颜色。
然后,在 Scaffold 的正文中添加一个 Center Widget。
之后,将 Container 指定为 Center Widget 的子元素。
现在,通过指定背景颜色、BorderRadius 等来装饰 Container。
然后,在 Container 的子元素中放置一张图片。

  1. SafeArea ->
  2. Scaffold ->
  3. Center ->
  4. Container ->
  5. AssetImage NetworkImage
英文:

Try to write Code by yourself I will give you a basic idea about how this type of SplashScreens can be built.

First Take Scaffold
Make the Scaffold background color to the background color of your SplashScreen.
Then add a Center Widget in the body of the Scaffold
After that specify Container as a child of Center Widget
Now Decorate the Container by specifying background color, BorderRadius etc
Then place an image in the child of the Container.

  1. Safearea ->
  2. Scaffold ->
  3. Center ->
  4. Container ->
  5. AssetImage or NetworkImage

huangapple
  • 本文由 发表于 2023年5月28日 10:48:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定