当我按下“查看更多”按钮时,什么也没有发生,我该怎么办,它应该在浏览器应用程序的url列表中启动一个网站,但是那没有发生,
import 'package:flutter/material.dart';
import 'package:wwdc/data.dart';
import 'dart:math';
import 'package:url_launcher/url_launcher.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
var cardAspectRatio = 12.0 / 16.0;
var widgetAspectRatio = cardAspectRatio * 1.2;
class _MyAppState extends State<MyApp> {
var currentPage = images.length - 1.0;
@override
Widget build(BuildContext context) {
PageController controller = PageController(initialPage: images.length - 1);
controller.addListener(() {
setState(() {
currentPage = controller.page;
});
});
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xFF1b1e44),
Color(0xFF2d3447),
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
tileMode: TileMode.clamp)),
child: Scaffold(
backgroundColor: Colors.black45,
body: SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(
height: 100,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Releases",
style: TextStyle(
color: Colors.white,
fontSize: 46.0,
fontFamily: "Calibre-Semibold",
letterSpacing: 1.0,
)),
],
),
),
Stack(
children: <Widget>[
CardScrollWidget(currentPage),
Positioned.fill(
child: PageView.builder(
itemCount: images.length,
controller: controller,
reverse: true,
itemBuilder: (context, index) {
return Container();
},
),
)
],
),
],
),
),
),
);
}
}
class CardScrollWidget extends StatelessWidget {
List<String> urls = [
'https://www.apple.com/watchos/watchos-preview/',
'https://www.apple.com/macos/big-sur-preview/',
'https://www.apple.com/ipados/ipados-preview/',
'https://www.apple.com/ios/ios-14-preview/'
];
var currentPage;
var padding = 20.0;
var verticalInset = 20.0;
//var k=0;
CardScrollWidget(this.currentPage);
@override
Widget build(BuildContext context) {
return new AspectRatio(
aspectRatio: widgetAspectRatio,
child: LayoutBuilder(builder: (context, contraints) {
var width = contraints.maxWidth;
var height = contraints.maxHeight;
var safeWidth = width - 2 * padding;
var safeHeight = height - 2 * padding;
var heightOfPrimaryCard = safeHeight;
var widthOfPrimaryCard = heightOfPrimaryCard * cardAspectRatio;
var primaryCardLeft = safeWidth - widthOfPrimaryCard;
var horizontalInset = primaryCardLeft / 2;
List<Widget> cardList = new List();
for (var i = 0; i < images.length; i++) {
var delta = i - currentPage;
bool isOnRight = delta > 0;
print(i);
var start = padding +
max(
primaryCardLeft -
horizontalInset * -delta * (isOnRight ? 15 : 1),
0.0);
var cardItem = Positioned.directional(
top: padding + verticalInset * max(-delta, 0.0),
bottom: padding + verticalInset * max(-delta, 0.0),
start: start,
textDirection: TextDirection.rtl,
child: ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Container(
decoration: BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(3.0, 6.0),
blurRadius: 10.0)
]),
child: AspectRatio(
aspectRatio: cardAspectRatio,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.asset(images[i], fit: BoxFit.cover),
Align(
alignment: Alignment.bottomLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(5.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(30)),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
padding: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: Text(title[i],
style: TextStyle(
color: Colors.white,
fontSize: 35.0,
)),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.all(5),
child: ButtonTheme(
// buttonColor: Colors.white,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
child: new Text(
"View More",
style: TextStyle(
color: Colors.black45,
fontSize: 25,
),
),
onPressed: () async {
String url = urls[i];
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
//i++;
print("inside");
},
)))
],
),
)
],
),
),
),
),
);
cardList.add(cardItem);
}
return Stack(
children: cardList,
);
}),
);
}
}