Anonymous
Динамические размеры с использованием Dart не применяют изменения в меньших пикселях.
Сообщение
Anonymous » 10 янв 2025, 18:35
Итак, я работаю над этим проектом Flutter и хочу установить динамические размеры, которые будут работать на устройствах разных размеров. Но у меня возникли некоторые проблемы, поскольку изменения на самом деле не применяются. Может быть, моя формула неправильная? Я следую инструкциям на YouTube.
Это основное устройство, на котором я основываюсь. Pixel 4 API 31 Android 12.0 ("S").
А это другое устройство. Pixel 2 API 31 Android 12.0 ("S")
Как видите, контейнер не центрирован.
Вот файл с размерами. Высота Pixel 4 составляет 781 дюйм.
Код: Выделить всё
import 'package:get/get.dart';
class Dimensions {
static double screenHeight = Get.context!.height;
static double screenWidth = Get.context!.width;
static double pageView = screenHeight/2.44;
static double pageViewContainer = screenHeight/3.55;
static double pageViewTextContainer = screenHeight/6.50;
//dynamic height padding and margin
static double height10 = screenHeight/78.1;
static double height15 = screenHeight/52.06;
static double height20 = screenHeight/39.05;
static double height30 = screenHeight/26.03;
static double height45 = screenHeight/17.35;
//dynamic width padding and margin
static double width10 = screenHeight/78.1;
static double width15 = screenHeight/52.06;
static double width20 = screenHeight/39.05;
static double width30 = screenHeight/26.03;
//dynamic fonts
static double font20 = screenHeight/39.05;
//dynamic radius
static double raidus15 = screenHeight/52.06;
static double radius20 = screenHeight/39.05;
static double radius30 = screenHeight/26.03;
}
А это страница еды.
Код: Выделить всё
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:food_delivery/utils/colors.dart';
import 'package:food_delivery/widgets/big_text.dart';
import 'package:food_delivery/widgets/icon_and_text.dart';
import 'package:food_delivery/widgets/small_text.dart';
import '../utils/dimensions.dart';
return Transform(
transform: matrix,
child: Stack(
children: [
Container (
height: Dimensions.pageViewContainer,
margin: EdgeInsets.only(left: Dimensions.width10, right: Dimensions.width10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius30),
color: index.isEven?Color(0xFF69c5df):Color(0xFF9294dcc),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("assets/image/food0.png"))
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: Dimensions.pageViewTextContainer,
margin: EdgeInsets.only(left: Dimensions.width30, right: Dimensions.width30, bottom: Dimensions.width30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0xFFe8e8e8),
blurRadius: 5.0,
offset: Offset(0, 5)
),
BoxShadow(
color: Colors.white,
offset: Offset(-5, 0)
),
BoxShadow(
color: Colors.white,
offset: Offset(5, 0)
)
]
),
child: Container(
padding: EdgeInsets.only(top: Dimensions.height15, left: Dimensions.width15, right: Dimensions.width15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BigText(text: "Chinese Side"),
SizedBox(height: Dimensions.height10,),
Row(
children: [
Wrap(
children: List.generate(5, (index) => Icon(Icons.star, color: AppColors.mainColor, size: 15,)),
),
SizedBox(width: Dimensions.height10),
SmallText(text: "4.5"),
SizedBox(width: Dimensions.height10),
SmallText(text: "1287"),
SizedBox(width: Dimensions.height10),
SmallText(text: "comments")
],
),
SizedBox(height: Dimensions.height20,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconAndTextWidget(
icon: Icons.circle_sharp,
text: "Normal",
iconColor: AppColors.iconColor1),
IconAndTextWidget(
icon: Icons.location_on,
text: "1.7 km",
iconColor: AppColors.mainColor),
IconAndTextWidget(
icon: Icons.access_time_rounded,
text: "32 mins",
iconColor: AppColors.iconColor2),
],
)
],
),
),
),
)
],
),
);
}
}
Может кто-нибудь мне помочь? Я только начинаю изучать Flutter и Dart и не знаю, что не так, и просто следую инструкциям шаг за шагом.
ТИА!!!
Подробнее здесь:
https://stackoverflow.com/questions/793 ... ler-pixels
1736523329
Anonymous
Итак, я работаю над этим проектом Flutter и хочу установить динамические размеры, которые будут работать на устройствах разных размеров. Но у меня возникли некоторые проблемы, поскольку изменения на самом деле не применяются. Может быть, моя формула неправильная? Я следую инструкциям на YouTube. Это основное устройство, на котором я основываюсь. Pixel 4 API 31 Android 12.0 ("S"). [img]https://i.sstatic.net/mLHEYwWD.png[/img] А это другое устройство. Pixel 2 API 31 Android 12.0 ("S") [img]https://i.sstatic.net/LhDQBmod.png[/img] Как видите, контейнер не центрирован. Вот файл с размерами. Высота Pixel 4 составляет 781 дюйм. [code]import 'package:get/get.dart'; class Dimensions { static double screenHeight = Get.context!.height; static double screenWidth = Get.context!.width; static double pageView = screenHeight/2.44; static double pageViewContainer = screenHeight/3.55; static double pageViewTextContainer = screenHeight/6.50; //dynamic height padding and margin static double height10 = screenHeight/78.1; static double height15 = screenHeight/52.06; static double height20 = screenHeight/39.05; static double height30 = screenHeight/26.03; static double height45 = screenHeight/17.35; //dynamic width padding and margin static double width10 = screenHeight/78.1; static double width15 = screenHeight/52.06; static double width20 = screenHeight/39.05; static double width30 = screenHeight/26.03; //dynamic fonts static double font20 = screenHeight/39.05; //dynamic radius static double raidus15 = screenHeight/52.06; static double radius20 = screenHeight/39.05; static double radius30 = screenHeight/26.03; } [/code] А это страница еды. [code]import 'package:dots_indicator/dots_indicator.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:food_delivery/utils/colors.dart'; import 'package:food_delivery/widgets/big_text.dart'; import 'package:food_delivery/widgets/icon_and_text.dart'; import 'package:food_delivery/widgets/small_text.dart'; import '../utils/dimensions.dart'; return Transform( transform: matrix, child: Stack( children: [ Container ( height: Dimensions.pageViewContainer, margin: EdgeInsets.only(left: Dimensions.width10, right: Dimensions.width10), decoration: BoxDecoration( borderRadius: BorderRadius.circular(Dimensions.radius30), color: index.isEven?Color(0xFF69c5df):Color(0xFF9294dcc), image: DecorationImage( fit: BoxFit.cover, image: AssetImage("assets/image/food0.png")) ), ), Align( alignment: Alignment.bottomCenter, child: Container( height: Dimensions.pageViewTextContainer, margin: EdgeInsets.only(left: Dimensions.width30, right: Dimensions.width30, bottom: Dimensions.width30), decoration: BoxDecoration( borderRadius: BorderRadius.circular(Dimensions.radius20), color: Colors.white, boxShadow: [ BoxShadow( color: Color(0xFFe8e8e8), blurRadius: 5.0, offset: Offset(0, 5) ), BoxShadow( color: Colors.white, offset: Offset(-5, 0) ), BoxShadow( color: Colors.white, offset: Offset(5, 0) ) ] ), child: Container( padding: EdgeInsets.only(top: Dimensions.height15, left: Dimensions.width15, right: Dimensions.width15), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ BigText(text: "Chinese Side"), SizedBox(height: Dimensions.height10,), Row( children: [ Wrap( children: List.generate(5, (index) => Icon(Icons.star, color: AppColors.mainColor, size: 15,)), ), SizedBox(width: Dimensions.height10), SmallText(text: "4.5"), SizedBox(width: Dimensions.height10), SmallText(text: "1287"), SizedBox(width: Dimensions.height10), SmallText(text: "comments") ], ), SizedBox(height: Dimensions.height20,), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconAndTextWidget( icon: Icons.circle_sharp, text: "Normal", iconColor: AppColors.iconColor1), IconAndTextWidget( icon: Icons.location_on, text: "1.7 km", iconColor: AppColors.mainColor), IconAndTextWidget( icon: Icons.access_time_rounded, text: "32 mins", iconColor: AppColors.iconColor2), ], ) ], ), ), ), ) ], ), ); } } [/code] Может кто-нибудь мне помочь? Я только начинаю изучать Flutter и Dart и не знаю, что не так, и просто следую инструкциям шаг за шагом. ТИА!!! Подробнее здесь: [url]https://stackoverflow.com/questions/79345666/dynamic-dimensions-using-dart-is-not-applying-changes-in-smaller-pixels[/url]