Flutter IconButton 删除左侧的填充以与标题文本对齐
Flutter IconButton Remove Padding on Left to Align with Title Texts
到目前为止,它只是在中间,即使填充边缘插入设置为零和框约束。
Row(children: [
Padding(
padding: const EdgeInsets.fromLTRB(
3, 3, 3, 6),
child: Container(
width: 150,
height: 30,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title Sub-title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontFamily:
'Roboto’,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(
0, 10, 0, 3),
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
),
],
),
尝试使用列树并根据需要调整填充
import 'package:flutter/material.dart';
import 'package:so_test/screen/child_page.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool visible = true;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: Text("Test obviously"),
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
child: Container(
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Sub Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: 5,
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
));
}
}
输出:
您可以将第一个 Container 保留在不同的列中,并为以下三个 children 创建单独的列。
到目前为止,它只是在中间,即使填充边缘插入设置为零和框约束。
Row(children: [
Padding(
padding: const EdgeInsets.fromLTRB(
3, 3, 3, 6),
child: Container(
width: 150,
height: 30,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title Sub-title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontFamily:
'Roboto’,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(
0, 10, 0, 3),
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
),
],
),
尝试使用列树并根据需要调整填充
import 'package:flutter/material.dart';
import 'package:so_test/screen/child_page.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool visible = true;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: Text("Test obviously"),
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
child: Container(
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Sub Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: 5,
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
));
}
}
输出:
您可以将第一个 Container 保留在不同的列中,并为以下三个 children 创建单独的列。