gpt4 book ai didi

How to fix Flutter layout issues?(如何解决颤振布局问题?)

转载 作者:bug小助手 更新时间:2023-10-25 19:29:01 29 4
gpt4 key购买 nike



I am having issues with the layout and don't really know how to fix it. I would be happy to get a hint based in the following code.

我对布局有问题,真的不知道如何修复它。我很高兴得到基于以下代码的提示。


big_text.dart file:

Big_ext.dart文件:


    import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:my_app/utils/dimensions.dart';


class BigText extends StatelessWidget {
final Color? color; //The question mark makes it optional
final String text;
final double size;
final TextOverflow overFlow;

//final double size;
//final TextOverflow overflow; // Corrected the typo in the property name


BigText({Key? key, this.color = const Color(0xFF332D2B),
required this.text,
this.size=0,
this.overFlow = TextOverflow.ellipsis
}): super(key: key); // Three dots called ellipses if there is a text overflow

@override
Widget build(BuildContext context) {
return Text(
text,
maxLines: 1,
overflow: overFlow,
style: TextStyle(
fontFamily: 'Roboto',
color: color,
fontSize: size==0?Dimensions.font20:size,
fontWeight: FontWeight.w400
),
);
}
}

The second python file is called "food_page_body.dart".

第二个python文件名为“Food_page_body.dart”。


    import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/controllers/popular_product_controller.dart';
import 'package:my_app/utils/dimensions.dart';
import 'package:my_app/widgets/app_column.dart';
import 'package:my_app/widgets/big_text.dart';
import 'package:my_app/widgets/icon_and_text_widget.dart';
import 'package:my_app/widgets/small_text.dart';
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/src/animation/animation_controller.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter/src/widgets/ticker_provider.dart';

class FoodPageBody extends StatefulWidget {
const FoodPageBody({Key? key}) : super(key: key);

@override
_FoodPageBodyState createState() => _FoodPageBodyState();
}

class _FoodPageBodyState extends State<FoodPageBody> {
PageController pageController = PageController(viewportFraction: 0.85);
var _currPageValue=0.0;
double _scaleFactor=0.8;
double _height=Dimensions.pageViewContainer;

@override
void initState(){
super.initState();
pageController.addListener(() {
setState(() {
_currPageValue=pageController.page!; //Get the value of the page
// print("Current Value is"+_currPageValue.toString());
});
});
}

// Remove the page from memory
@override
void dispose(){
pageController.dispose();
}


@override
Widget build(BuildContext context) {
return Column(
children: [
//slider section - // Create an instance of the get builder
GetBuilder<PopularProductController>(builder:(popularProducts){
return Container(
//color: Colors.redAccent, // Background color
height: Dimensions.pageView,
child: PageView.builder(
controller: pageController,
itemCount: popularProducts.popularProductList.length,
itemBuilder: (context, position) {
return _buildPageItem(position);
}),
);
}),

//dots
GetBuilder<PopularProductController>(builder: (popularProducts){
return DotsIndicator(
dotsCount: popularProducts.popularProductList.isNotEmpty ? popularProducts.popularProductList.length: 2,
//dotsCount: popularProducts.popularProductList.length,
//dotsCount: 5,
position: _currPageValue,
decorator: DotsDecorator(
activeColor: Color(0xFF80CBC4),
size: const Size.square(9.0),
activeSize: const Size(18.0, 9.0),
activeShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
),
);
}),

//popular text
SizedBox(height: Dimensions.height30,),
Container(
margin: EdgeInsets.only(left: Dimensions.width30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
BigText(text: "Popular"),
SizedBox(width: Dimensions.width10,),
Container(
margin: const EdgeInsets.only(bottom: 3),
child: BigText(text: ".", color:Colors.black26),
),
SizedBox(width: Dimensions.width10,),
Container(
margin: const EdgeInsets.only(bottom: 2),
child: SmallText(text: "Food pairing",),
)
],
),
),

//list of food and images
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true, //AlwaysScrollable..() oldugu zaman comment out yap
itemCount:10,
itemBuilder: (context, index){
return Container(
margin: EdgeInsets.only(left: Dimensions.width20, right: Dimensions.width20, bottom: Dimensions.height10),
child: Row(
children: [
//Image section
Container(
width: Dimensions.listViewImgSize,
height: Dimensions.listViewImgSize,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius20),
color: Colors.white38,
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("lib/assets/image/sushi.jpg")
)
)
),

//text container
Expanded(
child: Container(
height: Dimensions.listViewTextContSize,
//width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(Dimensions.radius20),
bottomRight: Radius.circular(Dimensions.radius20)
),
color: Colors.white,
),
child: Padding(
padding: EdgeInsets.only(left: Dimensions.width10, right: Dimensions.width10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, //vertical
children: [
BigText(text: "Nutritious fruit meal in Japan"),
SizedBox(height: Dimensions.height10,),
SmallText(text: "With japanese characteristics"),
SizedBox(height: Dimensions.height10,),

Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconAndTextWidget(icon: Icons.circle_sharp,
text: "Normal",
iconColor: Color(0xFFFFB74D)),

IconAndTextWidget(icon: Icons.location_on,
text: "1.7km",
iconColor: Color(0xFF80CBC4)),

IconAndTextWidget(icon: Icons.access_time_rounded,
text: "32min",
iconColor: Color(0xFFEF9A9A))
],
)
],
),
),
)
)
],
),
);
}),
],
);
}


// Zoom In and Zoom Out. And also scaling when we move it to left and right
Widget _buildPageItem(int index) {
Matrix4 matrix = new Matrix4.identity();
if (index==_currPageValue.floor()){
var currScale = 1-(_currPageValue-index)*(1-_scaleFactor);
var currTrans = _height*(1-currScale)/2;
matrix=Matrix4.diagonal3Values(1, currScale, 1)..setTranslationRaw(0, currTrans, 0);

}else if(index==_currPageValue.floor()+1){
var currScale = _scaleFactor+(_currPageValue-index+1)*(1-_scaleFactor);
var currTrans = _height*(1-currScale)/2;
matrix=Matrix4.diagonal3Values(1, currScale, 1);
matrix=Matrix4.diagonal3Values(1, currScale, 1)..setTranslationRaw(0, currTrans, 0);

}else if(index==_currPageValue.floor()-1){
var currScale = 1-(_currPageValue-index)*(1-_scaleFactor);
matrix=Matrix4.diagonal3Values(1, currScale, 1);
matrix=Matrix4.diagonal3Values(1, currScale, 1)..setTranslationRaw(0, currScale, 0);

}else{
var currScale=0.8;
matrix=Matrix4.diagonal3Values(1, currScale, 1)..setTranslationRaw(0, _height*(1-_scaleFactor)/2, 1);

}


return Transform(
transform: matrix,
child: Stack(
children: [
Container(
height: Dimensions.pageViewContainer,
margin: EdgeInsets.only(left: Dimensions.width10, right: Dimensions.width10), // Creates empty space between slides
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius30),
color: Colors.black,
//color: index.isEven ? Color(0xFF69c5df) : Color(0xFF9294cc),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage("lib/assets/image/food1.png")
)
)
),
Align(
alignment: Alignment.bottomCenter,
child: Container( // Thhe small widget in the main interface. It has a column with two rows below.
height: Dimensions.pageViewTextContainer,
margin: EdgeInsets.only(left: Dimensions.width30, right: Dimensions.width30, bottom: Dimensions.height30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius20),
color: Colors.white,
//Shadow property
boxShadow: [
BoxShadow(
color: Color(0xFFe8e8e8),
blurRadius: 5.0, //If it is 1, it is very very blurry
offset: Offset(0, 5)
),
BoxShadow(
color: Colors.white,
offset: Offset(-5, 0)
),
BoxShadow(
color: Colors.white,
offset: Offset(5, 0)
)
]//It takes list of childeren
//color: index.isEven ? Color(0xFF69c5df) : Color(0xFF9294cc),
),
child: AppColumn(text: "Turkish Side"),
),
)
],
),
);
}
}

For example, the "Popular" text can not be printed. It only prints the first letter "P". The screenshot of the "Layout Explorer" is given below. What would be the best approach to fix it? Thanks in advance!

例如,“流行”的文本不能打印。它只打印第一个字母“P”。“布局浏览器”的屏幕截图如下所示。解决这个问题的最佳方法是什么?提前谢谢!


flutter_layout_issue


更多回答
优秀答案推荐
更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com