我有一個使用 video_player 播放的本地 .mp4。我正在嘗試裁剪或覆寫它,使其看起來像視頻中心部分的圓圈,然后將其設為按鈕。我嘗試了 Stack、Containers w/ BoxDecoration:borderRadius、按鈕、ClipRRect 到圓角和覆寫的變體,但無濟于事。如果您運行代碼,您將看到視頻。我希望裁剪/疊加層剛好在太陽的邊緣邊界內。
video_player: ^2.4.2
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class HeaderSun extends StatefulWidget {
const HeaderSun({Key? key}) : super(key: key);
State<HeaderSun> createState() => _HeaderSunState();
}
class _HeaderSunState extends State<HeaderSun> {
late VideoPlayerController _controller;
late VideoPlayer sdo;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network('https://sdo.gsfc.nasa.gov/assets/img/latest/mpeg/latest_1024_0193.mp4');
_controller.setLooping(true);
_controller.setVolume(0.0);
_controller.initialize().then((_) {
_controller.play();
});
}
@override
Widget build(BuildContext context) {
sdo = VideoPlayer(_controller);
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
toolbarHeight: 120,
backgroundColor: Colors.black,
actions: [
Expanded(
child:
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 120,
width: 120,
decoration: BoxDecoration(
// shape: BoxShape.circle,
borderRadius: BorderRadius.circular(50),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(50.0),
clipBehavior: Clip.hardEdge,
child: IconButton(
iconSize: 120,
onPressed: () async {
await showDialog(
context: context,
builder: (_) {
return Dialog(
backgroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
child: sdo
),
);
} //SDOVideo()
);
},
icon: sdo
)//),
)
)
],
),
)
],
),
body: const Text('SDO 193'),
);
}
}
uj5u.com熱心網友回復:
您可以使用ClipRRect小部件:
ClipRRect(
borderRadius: BorderRadius.circular(60.0),
child: VideoPlayer(),
clipBehavior: Clip.hardEdge, // It's highly advisable to use this behavior to improve performance.
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/488621.html
