question_showdialog 0.0.2
question_showdialog: ^0.0.2 copied to clipboard
This widget is used for pop question module for video, audio, pdf and pptx.
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:question_showdialog/lib/showdialog.dart';
import 'package:video_player/video_player.dart';
void main(){
WidgetsFlutterBinding.ensureInitialized();
// SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
var isQ = false;
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return GetMaterialApp(debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: isQ?AppBar(
toolbarHeight: 50,
):AppBar(
toolbarHeight: 0,
),
body: VideoQuestion(),
),
);
}
}
class VideoQuestion extends StatefulWidget {
const VideoQuestion({Key? key}) : super(key: key);
@override
State<VideoQuestion> createState() => _VideoQuestionState();
}
var s1 = [
"What is the Topic Name?",
"Widget of this Week",
];
var s2 = [
"How many arguments in Draggable Widget?",
"What is the class should be added in Data?",
"What class is assigned to child field?",
"What is the class name for feedback?",
"What is the class name of the childWhenDragging?"
];
var s3 = [
"What widget is used with Draggable?",
"How many argument for Dragtarget Widget?"
];
var s4 = [
"How many widget learnt today?",
];
var s2_a = [
["4","2","1","3"],
["Color","int","object","All the above"],
["MyBlueBox","Any Class","None of these","int"],
["MyRoundedBlueBox","Any Class","None of these","int"],
["MyGreyBox","Any Class","None of these","int"],
];
var s3_a = [
["TextBox","DragTarget","None of these","All of these"],
["2","4","3","1"]
];
var s4_a = [
["4","2","1","10"]
];
var s1_a = [
["Draggable","TextField","Dropdown","Menu"],
["Draggable,TextField","Draggable,DragTarget","Dropdown,TextField","Menu,Button"]
];
var s1_a_bool = [
[false,false,false,false],
[false,false,false,false]
];
var s3_a_bool = [
[false,false,false,false],
[false,false,false,false]
];
var s4_a_bool = [
[false,false,false,false],
];
var s2_a_bool = [
[false,false,false,false],
[false,false,false,false],
[false,false,false,false],
[false,false,false,false],
[false,false,false,false],
];
//var items = [s1];
var vcout=0;
var items2= [
Text("1"),
Text("2"),
Text("3"),
Text("4"),
];
var qq = [s1,s2,s3,s4];
var qq_o = [s1_a,s2_a,s3_a,s4_a];
var qq_b = [s1_a_bool,s2_a_bool,s3_a_bool,s4_a_bool];
var a1_a_bool = [
[true,false,false,false],
[false,true,false,false]
];
var a2_a_bool = [
[true,false,false,false],
[false,false,false,true],
[false,true,false,false],
[false,true,false,false],
[false,true,false,false],
];
var a3_a_bool = [
[false,true,false,false],
[false,true,false,false]
];
var a4_a_bool = [
[false,true,false,false],
];
var ans = [
a1_a_bool,
a2_a_bool,
a3_a_bool,
a4_a_bool,
];
var totalQuestion = 0,correctQuestion=0;
class _VideoQuestionState extends State<VideoQuestion> {
late VideoPlayerController _controller;
PageController buttonCarouselController = PageController();
var questionCount=0;
var showSubmit = false;
var showPrev = false;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset('assets/test.mp4');
_controller.addListener(() {
setState(() {});
});
//_controller.setLooping(true);
_controller.initialize().then((_) => setState(() {
}));
_controller.play();
if(!_controller.value.isPlaying){
Timer.periodic(Duration(seconds: 1), (timer) {
var vale = _controller.value.position;
print(vale);
for(var i in time){
if(i == vale.inSeconds){
if(_controller.value.isPlaying){
showDialog(context: context, builder: (context){
return QuestionDialog(
sectionCount: vcout,
isRadioButton: true,
questionList: qq,
questionOptionList: qq_o,
questionCheckBoxList: qq_b,
nextPressed:(v,isSubmitButon,a,b) async{
print("====QuestionCo $b");
if(isSubmitButon){
vcout++;
var val = _controller.value.position.inSeconds;
// SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
await _controller.seekTo(Duration(seconds: val+1));
await _controller.play();
}
},
prevPressed:(v){}
);
});
}
_controller.pause().then((value){
setState(() {
// SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
isQ = true;
});
});
}
}
});
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
var time = [6,40,70,85];
var q = ["What is the Topic?","How many arguments in the Draggabfle Widget?","Where to land?","How many arguments in DragTarget","How many Widget in this topic?"];
var op = [["Draggable","TextField","Dropdown","Menu"],
[1,4,2,3],
["child","builder","dragtarge","children"],
[2,5,3,4],
[4,5,10,2]];
var st = 0;
quw(){
var size = MediaQuery.of(context).size;
return Container(
height: size.height,
width: size.width,
padding: EdgeInsets.all(10.0),
child: Card(
child: Column(
children: [
ElevatedButton(onPressed: () async{
// SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
var val = _controller.value.position.inSeconds;
// SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
await _controller.seekTo(Duration(seconds: val+1));
await _controller.play().then((value){
setState(() {
isQ = false;
});
});
}, child: Text("Submit"))
],
),
),
);
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
VideoPlayer(_controller),
_ControlsOverlay(controller: _controller),
VideoProgressIndicator(_controller, allowScrubbing: true,padding: EdgeInsets.only(top: 100)),
],
)
),
);
}
}
class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({required this.controller});
static const List<Duration> _exampleCaptionOffsets = <Duration>[
Duration(seconds: -10),
Duration(seconds: -3),
Duration(seconds: -1, milliseconds: -500),
Duration(milliseconds: -250),
Duration.zero,
Duration(milliseconds: 250),
Duration(seconds: 1, milliseconds: 500),
Duration(seconds: 3),
Duration(seconds: 10),
];
static const List<double> _examplePlaybackRates = <double>[
0.25,
0.5,
1.0,
1.5,
2.0,
3.0,
5.0,
10.0,
];
final VideoPlayerController controller;
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
AnimatedSwitcher(
duration: const Duration(milliseconds: 50),
reverseDuration: const Duration(milliseconds: 200),
child: controller.value.isPlaying
? const SizedBox.shrink()
: Container(
color: Colors.black26,
child: const Center(
child: Icon(
Icons.play_arrow,
color: Colors.white,
size: 100.0,
semanticLabel: 'Play',
),
),
),
),
GestureDetector(
onTap: () {
controller.value.isPlaying ? controller.pause() : controller.play();
var value = controller.value.position;
},
),
Align(
alignment: Alignment.topLeft,
child: PopupMenuButton<Duration>(
initialValue: controller.value.captionOffset,
tooltip: 'Caption Offset',
onSelected: (Duration delay) {
controller.setCaptionOffset(delay);
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<Duration>>[
for (final Duration offsetDuration in _exampleCaptionOffsets)
PopupMenuItem<Duration>(
value: offsetDuration,
child: Text('${offsetDuration.inMilliseconds}ms'),
)
];
},
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 16,
),
child: Text('${controller.value.captionOffset.inMilliseconds}ms'),
),
),
),
Align(
alignment: Alignment.topRight,
child: PopupMenuButton<double>(
initialValue: controller.value.playbackSpeed,
tooltip: 'Playback speed',
onSelected: (double speed) {
controller.setPlaybackSpeed(speed);
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<double>>[
for (final double speed in _examplePlaybackRates)
PopupMenuItem<double>(
value: speed,
child: Text('${speed}x'),
)
];
},
child: Padding(
padding: const EdgeInsets.symmetric(
// Using less vertical padding as the text is also longer
// horizontally, so it feels like it would need more spacing
// horizontally (matching the aspect ratio of the video).
vertical: 12,
horizontal: 16,
),
child: Text('${controller.value.playbackSpeed}x'),
),
),
),
],
);
}
}