如何约束颤动中的项目位置?

发布于 2025-01-17 09:43:47 字数 626 浏览 2 评论 0原文

我尝试制作一个小部件列表。它看起来像这样:

在此处输入图像描述

我知道 flutter 中没有约束布局之类的东西。但我需要一些东西将我的箭头图标放置在右侧的固定位置。简而言之,这是我的小部件代码:

Row(
children:[
  SizedBox(),
  Column(),//this is all the item on the left
  Spacer(),
  Expanded(// this is the heart and arrow button
   child: Column()
  )
]
)

我注意到,如果左侧的列太宽,我的箭头和心形图标就会移出直线。 输入图片这里的描述

如何将我的图标放在右侧的固定位置?

I try to make a list of widget. It look like this:

enter image description here

I know of no such thing as Constraint Layout in flutter. But I need something to position my arrow icon in a fixed position on the right. To put it simple, this is my widget code:

Row(
children:[
  SizedBox(),
  Column(),//this is all the item on the left
  Spacer(),
  Expanded(// this is the heart and arrow button
   child: Column()
  )
]
)

I notice that if my column on the left get too wide, my arrow and heart icon is shifted out of line.
enter image description here

How to put my icon in fixed position to the right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-01-24 09:43:47

在这里尝试一下,您必须与扩展的中间列包裹中间列,以便将最大可用空间

“在此处输入图像说明”

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const Center(
          child: MyStatefulWidget(),
        ),
      ),
    );
  }
}

/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  bool isChecked = false;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: 10,
      itemBuilder: (_, index) => Container(
        padding: EdgeInsets.all(15),
        margin: EdgeInsets.symmetric(vertical: 5),
        decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),border: Border.all(width: 1.5)),
        child: Row(
          children: [
            Container(
              width: 25,
              height: 40,
              color: Colors.black,
            ),
            Expanded(
              child: Column(children: [
              //put your children here
              ]),
            ),
            //this will be always on right
            Column(
              children: [
                Icon(Icons.heart_broken),
                Icon(Icons.chevron_right),
              ],
            )
          ],
        ),
      ),
    );
  }
}

here try this, You have to wrap middle column with expanded so it will take the maximum space available

enter image description here

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const Center(
          child: MyStatefulWidget(),
        ),
      ),
    );
  }
}

/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  bool isChecked = false;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: 10,
      itemBuilder: (_, index) => Container(
        padding: EdgeInsets.all(15),
        margin: EdgeInsets.symmetric(vertical: 5),
        decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),border: Border.all(width: 1.5)),
        child: Row(
          children: [
            Container(
              width: 25,
              height: 40,
              color: Colors.black,
            ),
            Expanded(
              child: Column(children: [
              //put your children here
              ]),
            ),
            //this will be always on right
            Column(
              children: [
                Icon(Icons.heart_broken),
                Icon(Icons.chevron_right),
              ],
            )
          ],
        ),
      ),
    );
  }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文