【发布时间】:2021-09-18 15:29:20
【问题描述】:
如何添加搜索选项,感谢点击后会添加一个新容器,目前点击后的代码在底部创建了一个新容器,但我还需要增加此选项并添加搜索选项。
在这种情况下,我是否必须结合点击和搜索选项来创建新容器?
我是 Flutter 的新手,任何帮助都会很有价值。
class ProfileView3 extends StatefulWidget {
const ProfileView3({Key? key}) : super(key: key);
@override
_ProfileView3State createState() => _ProfileView3State();
static Route<void> route() {
return MaterialPageRoute<void>(builder: (_) => ProfileView3());
}
}
class _ProfileView3State extends State<ProfileView3> {
Widget _profilePage(BuildContext context) {
return SafeArea(
child: Center(
child: Column(
children: [
_Text_2(),
_buildValues(),
_Text_4(),
_buildPickeds()
],
),
),
);
// });
}
List<String> values = [
'Lion',
'Tiger',
'Flaming',
];
List<String> pickedValues = [];
Widget _buildValues() {
return Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Wrap(
spacing: 8.0,
// line interval
runSpacing: 8.0,
children: values
.map(
(value) => GestureDetector(
onTap: () {
if (pickedValues.contains(value)) {
//delete when click part of value
//
// pickedValues.remove(value);
} else {
pickedValues.add(value);
}
setState(() {});
},
child: Container(
decoration: const BoxDecoration(
color: Colors.deepPurpleAccent,
borderRadius: BorderRadius.all(Radius.circular(5.0))),
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
child: Text(
value,
style: TextStyle(color: Colors.white),
// fontWeight: FontWeight.bold
),
),
),
)
.toList(),
),
],
),
);
}
Widget _buildPickeds() {
return Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Wrap(
spacing: 8.0,
// line interval
runSpacing: 8.0,
children: pickedValues
.map(
(value) => GestureDetector(
onTap: () {
if (pickedValues.contains(value)) {
pickedValues.remove(value);
} else {
pickedValues.add(value);
}
setState(() {});
},
child: Container(
decoration: BoxDecoration(
color: Colors.black26,
border: Border.all(
color: Colors.purpleAccent, // set border color
width: 1.5),
borderRadius: BorderRadius.all(Radius.circular(5.0))),
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 5,
),
child: RichText(
text: TextSpan(
style: Theme.of(context).textTheme.body1,
children: [
const WidgetSpan(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 2.0),
child: Icon(Icons.check),
),
),
TextSpan(text: value),
const WidgetSpan(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 2.0),
child: Icon(Icons.close),
),
),
],
),
)
),
),
)
.toList(),
),
],
),
);
【问题讨论】:
标签: flutter dart flutter-layout flutter-dependencies flutter-animation