提问人:Just Watch 提问时间:11/5/2023 更新时间:11/5/2023 访问量:22
Flutter 按钮选择在 Gridview on Tv App 中的错误位置开始
Flutter Button selection starting wrong place in Gridview on Tv App
问:
错误的选择开始我打开频道列表并按向下箭头,但按钮选择从底部开始。我尝试了gridview的反向命令。然后它从顶部开始,但从列表的中间开始。错误的选择开始反转如果您能提供帮助,我将不胜感激。
return Scaffold(
backgroundColor: Colors.black,
body: RawKeyboardListener(
autofocus: false,
focusNode: FocusNode(), // <-- more magic
onKey: (event) {
print(event.data.logicalKey);
if (visible == false) {
if (event.runtimeType.toString() == 'RawKeyUpEvent') {
if (event.data.logicalKey == LogicalKeyboardKey.arrowDown) {
int index =
live.indexWhere((item) => item.link == widget.url);
print(index);
print(widget.url);
index = index - 1;
print(index);
print(index);
print('livin uzunluğu ${live.length}');
if (index < 0) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => watchStream2(
url: live.last.link,
FilmOrLive: 'Live',
)),
(Route<dynamic> route) => false,
);
} else {
String newUrl = live.elementAt(index).link.toString();
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => watchStream2(
url: newUrl,
FilmOrLive: 'Live',
)),
(Route<dynamic> route) => false,
);
}
}
if (event.data.logicalKey == LogicalKeyboardKey.arrowUp) {
int index =
live.indexWhere((item) => item.link == widget.url);
print(index);
print(widget.url);
index = index + 1;
print(index);
print(index);
print('livin uzunluğu ${live.length}');
if (index > live.length - 1) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => watchStream2(
url: live.first.link,
FilmOrLive: 'Live',
)),
(Route<dynamic> route) => false,
);
} else {
String newUrl = live.elementAt(index).link.toString();
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => watchStream2(
url: newUrl,
FilmOrLive: 'Live',
)),
(Route<dynamic> route) => false,
);
}
print('yukarı');
setState(() {});
}
if (event.data.logicalKey == LogicalKeyboardKey.arrowLeft) {}
if (event.data.logicalKey == LogicalKeyboardKey.arrowRight) {}
}
}
},
child: Stack(
children: [
YoYoPlayer2(
aspectRatio: 16 / 9,
url: widget.url,
videoStyle2: VideoStyle2(
qualityStyle: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.white,
),
forwardAndBackwardBtSize: 30.0,
playButtonIconSize: 40.0,
playIcon: Icon(
Icons.play_circle,
size: 40.0,
color: Colors.white,
),
pauseIcon: Icon(
Icons.pause_circle,
size: 40.0,
color: Colors.white,
),
videoQualityPadding: EdgeInsets.all(5.0),
),
videoLoadingStyle: VideoLoadingStyle(
loading: Center(
child: CircularProgressIndicator(
color: Colors.red,
)),
),
allowCacheFile: true,
onCacheFileCompleted: (files) {
print('Cached file length ::: ${files?.length}');
if (files != null && files.isNotEmpty) {
for (var file in files) {
print('File path ::: ${file.path}');
}
}
},
onCacheFileFailed: (error) {
print('Cache file error ::: $error');
},
),
RawKeyboardListener(
autofocus: true,
focusNode: FocusNode(), // <-- more magic
onKey: (event) {
print(event.data.logicalKey);
if (visible == false) {
if (event.runtimeType.toString() == 'RawKeyDownEvent') {
if (event.data.logicalKey == LogicalKeyboardKey.select) {
visible = true;
setState(() {});
}
}
}
if (visible == true) {
if (event.runtimeType.toString() == 'RawKeyUpEvent') {
if (event.data.logicalKey == LogicalKeyboardKey.arrowUp) {
myFocusNode;
}
if (event.data.logicalKey ==
LogicalKeyboardKey.arrowDown) {
myFocusNode;
}
}
}
},
child: Visibility(
visible: visible,
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: Container(
width: MediaQuery.of(context).size.width / 4,
height: MediaQuery.of(context).size.height / 1,
color: Colors.black.withOpacity(0.5),
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height / 100),
child: GridView(
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: BouncingScrollPhysics(),
primary: true,
reverse: true,
// Pitch between vertical widgets
// GridView within the margin
padding: EdgeInsets.all(5.0),
// Widget quantity
// sub-Widget wide proportion
// Subwood list
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisSpacing:
MediaQuery.of(context).size.height /
1000,
childAspectRatio: 4),
children: live.map((ml) {
return ElevatedButton(
autofocus: true,
focusNode: myFocusNode,
onPressed: null,
style: ElevatedButton.styleFrom(
shape: LinearBorder.end()),
child: Column(
children: [
InkWell(
focusColor: Colors.red,
onTap: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) =>
watchStream2(
url: ml.link,
FilmOrLive: 'Live',
)),
(Route<dynamic> route) => false,
);
},
child: Ink(
child: Card(
shape: RoundedRectangleBorder(
side: BorderSide(
color: Colors.transparent),
borderRadius: BorderRadius.all(
Radius.circular(10))),
child: Container(
width: MediaQuery.of(context)
.size
.width /
1,
height: MediaQuery.of(context)
.size
.height /
11,
decoration: BoxDecoration(
color: Colors.indigo[900],
borderRadius:
BorderRadius.all(
Radius.circular(10))),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(
context)
.size
.width /
75,
right: MediaQuery.of(
context)
.size
.width /
50),
child: Align(
alignment:
Alignment.centerLeft,
child: Container(
width: MediaQuery.of(
context)
.size
.width /
25,
child:
CachedNetworkImage(
imageUrl: ml.assets,
placeholder: (context,
url) =>
new CircularProgressIndicator(),
errorWidget: (context,
url,
error) =>
new Icon(Icons
.error),
)),
),
),
Center(
child: Text(
ml.name,
style: TextStyle(
fontSize: MediaQuery.of(
context)
.size
.width /
90,
color: Colors.white,
fontWeight:
FontWeight.bold,
fontStyle:
FontStyle.italic),
),
),
],
),
),
))),
],
),
);
}).toList()),
),
),
)),
),
],
),
),
选择必须从顶部开始,列表顺序必须正确
答: 暂无答案
评论