【发布时间】:2021-10-12 20:51:02
【问题描述】:
我正在尝试学习如何设计侧边栏,我在网上找到了这张图片。我已经成功开发了一个简单的侧边栏,但无法完全像这样设计。由于我是 Flutter 的新手,所以我不知道如何在点击时添加此曲线形状和动画。这是我需要你帮助的地方。
这是我到目前为止所做的:
class HomeScreen extends StatefulWidget {
const HomeScreen({Key key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Home',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.red.withOpacity(0.3),
),
backgroundColor: Colors.red.withOpacity(0.3),
body: Row(
children: [
sideBar(),
],
),
);
}
Widget sideBar() {
final List<String> items = ['Snacks', 'Drinks', 'Food'];
return Container(
color: Colors.white,
child: Column(
children: items
.map((e) => Padding(
padding: const EdgeInsets.all(14.0),
child: GestureDetector(
onTap: () {
setState(() {
_selectedIndex = items.indexOf(e);
});
},
child: Row(
children: [
RotatedBox(quarterTurns: 3, child: Text(e)),
if (items.indexOf(e) == _selectedIndex)
const Padding(
padding: EdgeInsets.only(left: 8.0),
child: CircleAvatar(
backgroundColor: Colors.deepOrange,
radius: 5.0,
),
)
],
),
),
))
.toList(),
),
);
}
}
这是输出:
【问题讨论】:
标签: flutter android-studio dart user-interface sidebar