Column
다양한 수의 타이머를 사용 하는 Flutter 가 있습니다. 하나의 타이머가 필요하면 결과가 원하는 것처럼 보입니다.
그러나 두 개의 타이머를 추가하면 오버플로가 발생합니다.
두 번째 경우에는 타이머가 축소되어 사용 가능한 공간을 차지하고 싶습니다. 타이머가 4 개인 경우 두 개의 행과 두 개의 열을 표시하는 것이 이상적입니다.
나는 내 타이머 FittedBox
를 내가 맞추기 위해 설정 한 것으로 감싸려고 시도했지만 BoxFit.fitHeight
원하는 결과를 얻지 못했습니다. 그 밖에 무엇을해야합니까?
주석에서 요청한대로 Wrap을 사용한 코드 :
Wrap(
children: state.currentTimers
.map((selectedTimer) => TimerSessionWidget(selectedTimer))
.toList(),
);
class TimerSessionWidget extends StatefulWidget {
@override
_SelectedTimerState createState() => _SelectedTimerState(_selectedTimer);
final TimerSession _selectedTimer;
TimerSessionWidget(this._selectedTimer);
}
class _SelectedTimerState extends State {
final TimerSession _selectedTimer;
_SelectedTimerState(this._selectedTimer);
@override
Widget build(BuildContext context) {
return FittedBox(
fit: BoxFit.fitHeight,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
behavior: HitTestBehavior.deferToChild,
onTap: () {
if (_selectedTimer.loadedTimerBloc.state is VirginTimerState) {
_selectedTimer.loadedTimerBloc.add(StartTimerAction());
} else if (_selectedTimer.loadedTimerBloc.state
is FinishedTimerState) {
_selectedTimer.stopAlarmSound();
}
},
child: BlocProvider(
builder: (context) {
return _selectedTimer.loadedTimerBloc;
},
child: FittedBox(
fit: BoxFit.fitHeight,
child: Container(
height: 200,
width: 200,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 5.0,
)),
child: Stack(children: [
Align(
alignment: Alignment.center,
child: DurationDisplayWidget(_selectedTimer)),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: TimerActionWidget())),
Align(
alignment: Alignment.topRight,
child: RemoveTimerWidget(_selectedTimer),
)
])),
),
),
),
),
);
}
}
Column
아이들을 아래로 감싸 야합니다.Expanded
"확장 된 위젯을 사용하면 행, 열 또는 Flex의 하위 항목이 확장되어 주 축을 따라 사용 가능한 공간을 채 웁니다 (예 : 행의 경우 가로로, 열의 경우 세로로). 여러 하위 항목이 확장 된 경우 사용 가능한 공간은 다음과 같습니다. 플렉스 팩터에 따라 나누어집니다. " from https://api.flutter.dev/flutter/widgets/Expanded-class.html
예 :
import 'package:flutter/material.dart';
class Demo extends StatefulWidget {
@override
MyHomePageState createState() => new MyHomePageState();
}
class MyHomePageState extends State<Demo> {
@override
Widget build(BuildContext context) {
return Column(children: <Widget>[
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
Expanded(
child: Container(
child: Container(
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQgQu8nlAEzW63m0pKcq9csbtk-3ni_QlvW4uy6DgeaWbO4Fze1")))),
]);
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다