dart 如何在容器的侧面添加按钮

k3fezbri  于 2023-06-19  发布在  其他
关注(0)|答案(3)|浏览(102)

我正在创建用户界面的帐户页面与订单列表。我需要添加箭头按钮到篮子部件的右侧。我创建了3行列,但我不知道如何添加箭头按钮的右侧。

class BasketItem extends StatelessWidget {
  const BasketItem({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10),
      margin: EdgeInsets.symmetric(horizontal: 10, vertical: 2),
      height: 95,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10)
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('#462', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700]),),
              Text('Processing', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700]),),
            ],
          ),
          SizedBox(height: 15),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('299.99', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700], fontSize: 18),),
              Text('2023-09-21', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700]),),
            ],
          ),
          SizedBox(height: 5),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('1 item', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700]),),
              Text('09:31 PM', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey[700]),),
            ],
          ),
        ],
      ),
    );
  }
}
1bqhqjot

1bqhqjot1#

您可以在这个例子中尝试使用卡片和列。这是最基本的方法,你可以尝试学习其他的方法。您可以更改字体大小和列间距。

Card(
                  color: Colors.teal,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                       Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text("#462"),
                    SizedBox(height: MediaQuery.of(context).size.height * 0.01),
                    Text("2392"),
                    SizedBox(height: MediaQuery.of(context).size.height * 0.01),
                    Text("1 items"),
                  ],
                ),
                SizedBox(width: MediaQuery.of(context).size.width * 0.3),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text("Processing"),
                    SizedBox(height: MediaQuery.of(context).size.height * 0.01),
                    Text("2020-05-19"),
                    SizedBox(height: MediaQuery.of(context).size.height * 0.01),
                    Text("9:34 PM"),
                  ],
                ),
                        Icon(Icons.arrow_forward),
                      ],
                    ),
                  ),
                ),
c90pui9n

c90pui9n2#

Column Package 为Row,并将Column展开为Expanded
完整代码:-

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'List',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      debugShowCheckedModeBanner: false,
      home: const BasketItem(),
    );
  }
}

class BasketItem extends StatelessWidget {
  const BasketItem({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Container(
          padding: const EdgeInsets.all(10),
          margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(10)),
          height: 95,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '#462',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700]),
                        ),
                        Text(
                          'Processing',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700]),
                        ),
                      ],
                    ),
                    const SizedBox(height: 15),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '299.99',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700],
                              fontSize: 18),
                        ),
                        Text(
                          '2023-09-21',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700]),
                        ),
                      ],
                    ),
                    const SizedBox(height: 5),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '1 item',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700]),
                        ),
                        Text(
                          '09:31 PM',
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey[700]),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 15),
              const Icon(Icons.arrow_right_sharp)
            ],
          ),
        ),
      ),
    );
  }
}

输出:-

nbysray5

nbysray53#

这可以通过ListTile Widget轻松实现。

Sudo代码

ListTile(
            title: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('John Doe'),
                Text('john.doe@example.com'),
              ],
            ),
            trailing: Icon(Icons.arrow_forward),
            onTap: () {
              // HANDLE ON TAP 
            },
          ),

**title:**可以取任意一个Widget作为子节点。您可以在这里替换现有代码。

相关问题