如何在单选列表磁贴中添加尾随图标
How to add trailng icon in radio list tile flutter
我正在使用 RadioListTile
来显示带有单选按钮的动态数据,但是我想要 来显示带有用于编辑列表数据的尾随图标的相同列表。
你能帮我如何在 flutter 中做到这一点吗?
RadioListTile(
groupValue: _currentIndex,
title: Text(
// addres["address_1"],
addres["firstname"] +
addres["lastname"] +
addres["address_1"] +
addres["city"] +
addres["country"],
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(color: Colors.black, fontSize: 16.0),
),
value: int.parse(addres["address_id"]),
onChanged: (val) {
setState(() {
_currentIndex = val;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PickanAddresspage(selected_address: addres['address_id'],)));
});
},
)
在 title 中,您可以使用 Row 来包裹 Text 和 Icon
使用 Expanded 和 flex 来控制你需要的宽度
代码片段
title: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
"firstname" +
"lastname" +
"address_1" +
"city" +
"country234123412344523523452542345234523523542345245234523452345235234523452345245234523452452542",
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(color: Colors.black, fontSize: 16.0),
),
),
Expanded(
flex: 1,
child: InkWell(
child: Icon(
Icons.audiotrack,
color: Colors.green,
size: 30.0,
),
),
)
],
)
完整测试代码
// Flutter code sample for
// ![RadioListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile.png)
//
// This widget shows a pair of radio buttons that control the `_character`
// field. The field is of the type `SingingCharacter`, an enum.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
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: MyStatefulWidget(),
),
);
}
}
enum SingingCharacter { lafayette, jefferson }
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
SingingCharacter _character = SingingCharacter.lafayette;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RadioListTile<SingingCharacter>(
title: const Text('Lafayette'),
value: SingingCharacter.lafayette,
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
"firstname" +
"lastname" +
"address_1" +
"city" +
"country234123412344523523452542345234523523542345245234523452345235234523452345245234523452452542",
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(color: Colors.black, fontSize: 16.0),
),
),
Expanded(
flex: 1,
child: InkWell(
child: Icon(
Icons.audiotrack,
color: Colors.green,
size: 30.0,
),
),
)
],
),
value: SingingCharacter.jefferson,
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
});
},
),
],
);
}
}
我正在使用 RadioListTile
来显示带有单选按钮的动态数据,但是我想要 来显示带有用于编辑列表数据的尾随图标的相同列表。
你能帮我如何在 flutter 中做到这一点吗?
RadioListTile( groupValue: _currentIndex, title: Text( // addres["address_1"], addres["firstname"] + addres["lastname"] + addres["address_1"] + addres["city"] + addres["country"], overflow: TextOverflow.ellipsis, maxLines: 3, style: TextStyle(color: Colors.black, fontSize: 16.0), ), value: int.parse(addres["address_id"]), onChanged: (val) { setState(() { _currentIndex = val; Navigator.push( context, MaterialPageRoute( builder: (context) => PickanAddresspage(selected_address: addres['address_id'],))); }); }, )
在 title 中,您可以使用 Row 来包裹 Text 和 Icon
使用 Expanded 和 flex 来控制你需要的宽度
代码片段
title: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
"firstname" +
"lastname" +
"address_1" +
"city" +
"country234123412344523523452542345234523523542345245234523452345235234523452345245234523452452542",
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(color: Colors.black, fontSize: 16.0),
),
),
Expanded(
flex: 1,
child: InkWell(
child: Icon(
Icons.audiotrack,
color: Colors.green,
size: 30.0,
),
),
)
],
)
完整测试代码
// Flutter code sample for
// ![RadioListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile.png)
//
// This widget shows a pair of radio buttons that control the `_character`
// field. The field is of the type `SingingCharacter`, an enum.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
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: MyStatefulWidget(),
),
);
}
}
enum SingingCharacter { lafayette, jefferson }
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
SingingCharacter _character = SingingCharacter.lafayette;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RadioListTile<SingingCharacter>(
title: const Text('Lafayette'),
value: SingingCharacter.lafayette,
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
});
},
),
RadioListTile<SingingCharacter>(
title: Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
"firstname" +
"lastname" +
"address_1" +
"city" +
"country234123412344523523452542345234523523542345245234523452345235234523452345245234523452452542",
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(color: Colors.black, fontSize: 16.0),
),
),
Expanded(
flex: 1,
child: InkWell(
child: Icon(
Icons.audiotrack,
color: Colors.green,
size: 30.0,
),
),
)
],
),
value: SingingCharacter.jefferson,
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
});
},
),
],
);
}
}