我在下面的代码中插入导航链接时遇到问题。我想学习如何在第二个中插入导航链接
onPressed: () {
//TODO(实现)。}
ListView 小部件:已批准、待定等是应包含指向其他页面的链接的项目。这些页面将通过单击 FontAwesome.chevronRight 访问
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class AppTab2 extends StatefulWidget {
@override
_AppTab2State createState() => _AppTab2State();
}
class _AppTab2State extends State<AppTab2> {
PageController _pageController = PageController(initialPage: 2);
@override
build(BuildContext context) {
final Map<String, Widget> pages = <String, Widget>{
'My Music': Center(
child: Text('My Music not implemented'),
),
'Shared': Center(
child: Text('Shared not implemented'),
),
'Feed': Feed(),
};
TextTheme textTheme = Theme.of(context).textTheme;
return Stack(
children: [
Container(
decoration: BoxDecoration(
// Gradient color the background
gradient: LinearGradient(
begin: FractionalOffset.topCenter,
end: FractionalOffset.bottomCenter,
colors: [
const Color.fromARGB(255, 253, 72, 72),
const Color.fromARGB(255, 87, 97, 249),
],
stops: [0.0, 1.0],
)),
// child: Align(
// alignment: FractionalOffset.bottomCenter,
// child: Container(
// padding: const EdgeInsets.all(10.0),
// child: Text(
// 'Demo',
// style: textTheme.headline.copyWith(
// color: Colors.grey.shade800.withOpacity(0.8),
// fontWeight: FontWeight.bold,
// ),
// ),
// ),
// ),
),
Scaffold(
backgroundColor: Colors.white,
// appBar: AppBar(
// backgroundColor: const Color(0x00000000),
// elevation: 0.0,
// leading: Center(
// child: ClipOval(
// child: Image.network(
// 'http://i.imgur.com/TtNPTe0.jpg',
// ),
// ),
// ),
// actions: [
// IconButton(
// icon: Icon(Icons.add),
// onPressed: () {
// // TODO: implement
// },
// ),
// ],
//// title: const Text('tofu\'s songs'),
// bottom: CustomTabBar(
// pageController: _pageController,
// pageNames: pages.keys.toList(),
// ),
// ),
body: PageView(
controller: _pageController,
children: pages.values.toList(),
),
),
],
);
}
}
class CustomTabBar extends AnimatedWidget implements PreferredSizeWidget {
CustomTabBar({this.pageController, this.pageNames})
: super(listenable: pageController);
final PageController pageController;
final List<String> pageNames;
@override
final Size preferredSize = Size(0.0, 40.0);
@override
Widget build(BuildContext context) {
TextTheme textTheme = Theme.of(context).textTheme;
return Container(
height: 40.0,
margin: const EdgeInsets.all(10.0),
padding: const EdgeInsets.symmetric(horizontal: 20.0),
decoration: BoxDecoration(
color: Colors.grey.shade800.withOpacity(0.5),
borderRadius: BorderRadius.circular(20.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(pageNames.length, (int index) {
return InkWell(
child: Text(pageNames[index],
style: textTheme.subhead.copyWith(
fontSize: 30.0,
fontFamily: 'OpenSans',
color: Colors.white.withOpacity(
index == pageController.page ? 1.0 : 0.2,
),
)),
onTap: () {
pageController.animateToPage(
index,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
});
}),
),
);
}
}
class Feed extends StatefulWidget {
@override
_FeedState createState() => _FeedState();
}
class _FeedState extends State<Feed> {
@override
Widget build(BuildContext context) {
return ListView(
children: [
Content(
title: 'Approved',
),
Content(
title: 'Pending',
),
Content(
title: 'Published',
),
Content(
title: 'Withdrawn',
),
Content(
title: 'Declined',
),
Content(
title: 'Content Rights',
),
],
);
}
}
class Content extends StatefulWidget {
const Content({
this.title,
});
final String title;
@override
_ContentState createState() => _ContentState();
}
class _ContentState extends State<Content> {
@override
Widget build(BuildContext context) {
TextTheme textTheme = Theme.of(context).textTheme;
return Container(
margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
decoration: BoxDecoration(
color: Colors.grey.shade300.withOpacity(0.5),
borderRadius: BorderRadius.circular(5.0),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
// Container(
// margin:
// const EdgeInsets.only(top: 4.0, bottom: 4.0, right: 10.0),
// child: CircleAvatar(
// backgroundImage: NetworkImage(
// 'http://thecatapi.com/api/images/get?format=src'
// '&size=small&type=jpg#${title.hashCode}'),
// radius: 20.0,
// ),
// ),
SizedBox(
height: 15.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(widget.title, style: textTheme.subhead),
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 5.0),
child: InkWell(
child: Icon(
FontAwesomeIcons.chevronRight,
size: 25.0,
color: Colors.deepPurpleAccent,
),
onTap: () {
// TODO(implement)
},
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 5.0),
child: InkWell(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
// Icon(Icons.favorite, size: 25.0),
// Text('${likes ?? ''}'),
],
),
onTap: () {
// TODO(implement)
},
),
),
],
),
));
}
}
