我正在構建一個語言應用程式。申請如下:

有“你今天過得怎么樣?” 他在寫作。但是有一個溢位問題,因為它不適合。
如果溢位,我希望它自動進入底線。我怎樣才能做到這一點?
代碼:
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:getwidget/getwidget.dart';
class selamlasmaLearn_2 extends StatefulWidget {
@override
State<selamlasmaLearn_2> createState() => _selamlasmaLearn_1State();
}
class _selamlasmaLearn_1State extends State<selamlasmaLearn_2> {
final CarouselController _controller = CarouselController();
List<wordAndMeaning> wordsList = [
wordAndMeaning("How's it going?", "Nas?l gidiyor?", false),
wordAndMeaning("How's your day?", "Günün nas?ld??", false),
wordAndMeaning("How's your day going?", "Günün nas?l gidiyor?", false),
wordAndMeaning("Nice to see you", "Seni g?rmek güzel", false),
wordAndMeaning("It's been a while", "G?rü?meyeli uzun zaman oluyor", false),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.amber[500],
bottomOpacity: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.pop(context);
},
),
title: Text("Selamlama", style: TextStyle(fontSize: 25),),
),
backgroundColor: Colors.amber,
body: Builder(builder: (context) {
final double height = MediaQuery.of(context).size.height - 160;
return Column(
children: [
Expanded(
child: CarouselSlider(
carouselController: _controller,
options: CarouselOptions(
height: height,
viewportFraction: 1.0,
enlargeCenterPage: false,
),
items: wordsList.map((wordAndMeaning word) {
return Expanded(
child: Builder(
builder: (BuildContext context) {
return Container(
width: 45, // <<<<<<<<<<<<<<<<!!!!!!!
decoration: BoxDecoration(color: Colors.amber),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
if (word.showMeaning) ...[
Text(word.meaning,
style: TextStyle(
fontSize: MediaQuery.of(context).size.width - 200, color: Colors.white)),
Text(word.word,
style:
TextStyle(fontSize: 20, color: Colors.white)),
],
if (!word.showMeaning) ...[
Text(word.word,
style: TextStyle(
fontSize: 45, color: Colors.white)),
],
],
),
const SizedBox(
width: 10,
),
IconButton(
icon: Icon(Icons.remove_red_eye_sharp),
color: Colors.white,
iconSize: 25,
onPressed: () {
setState(() {
word.showMeaning = !word.showMeaning;
});
},
),
],
),
);
},
),
);
}).toList(),
),
),
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
color: Colors.amber[300],
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(10),
),
width: 130,
height: 60,
child: Container(
child: GFButton(
icon: Icon(Icons.arrow_back_ios),
text: "Geri", textStyle: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontSize: 24),
// borderi kapatma:
onPressed: () => _controller.previousPage(
duration: const Duration(milliseconds: 100),
curve: Curves.easeInCirc,
),
size: GFSize.LARGE,
),
),
),
SizedBox(
width: 10,
),
SizedBox(
width: 10,
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(10),
),
width: 130,
height: 60,
child: Container(
child: GFButton(
icon: Icon(Icons.arrow_forward_ios),
text: "?leri", textStyle: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontSize: 24),
onPressed: () => _controller.nextPage(
duration: const Duration(milliseconds: 100),
curve: Curves.easeInCirc,
),
size: GFSize.LARGE,
),
),
),
],
),
],
),
)
],
);
}),
);
}
}
class wordAndMeaning {
String word;
String meaning;
bool showMeaning;
wordAndMeaning(this.word, this.meaning, this.showMeaning);
}
文本的大小在第 54 行確定。我還注釋掉了確定大小的代碼。
在此先感謝您的幫助。
uj5u.com熱心網友回復:
您可以使用Flexible或Expanded小部件。
Expanded(
child: Text("How's it going?"),
)
要么
Flexible(
child: Text("How's it going?"),
)
兩種方法都有各自的優點,但是Flexible小部件更可取,因為它根據 Text 可以占用的方式呈現小部件。
uj5u.com熱心網友回復:
將您的文本小部件添加到擴展或靈活小部件中
Row(
children: [
Expanded(
child: Text(
'Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!',
),
),
],
),
結果螢屏->
嘗試添加您的 Inside Row 小部件,Expanded或在此處或此處或此處或此處或此處Flexible參考我的答案希望它對您有所幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/433476.html
