写一个flutter示例.使用Scaffold来布局页面,appbar有标题和回退按钮,有一个右侧边栏,侧边栏是一个频道列表数组,点击侧边栏里的频道,appbar标题显示当前频道名称,body是视频播放,点击侧边栏频道显示不同视频,使用fijkplayer插件来播放视频
时间: 2023-05-27 12:02:12 浏览: 80
一个示例应用程序使用flutter展示分类app
5星 · 资源好评率100%
import 'package:flutter/material.dart';
import 'package:fijkplayer/fijkplayer.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
FijkPlayer player;
List<String> channels = ['频道1', '频道2', '频道3', '频道4'];
String currentChannel = '频道1';
@override
void initState() {
super.initState();
player = FijkPlayer();
}
@override
void dispose() {
player.release();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(currentChannel),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {},
),
),
body: FijkView(
player: player,
fit: FijkFit.fitHeight,
),
endDrawer: Drawer(
child: ListView.builder(
itemCount: channels.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(channels[index]),
onTap: () {
setState(() {
currentChannel = channels[index];
});
Navigator.pop(context);
},
);
},
),
),
);
}
}
阅读全文