mirror of
https://github.com/jakobkordez/s5_practice.git
synced 2025-05-27 22:20:31 +00:00
WIP
This commit is contained in:
parent
ce66ad3391
commit
2bb0db8d63
@ -8,6 +8,10 @@ part 'generator_state.dart';
|
||||
class GeneratorCubit extends Cubit<GeneratorState> {
|
||||
GeneratorCubit() : super(const GeneratorPractice(singleCategory: false));
|
||||
|
||||
void setPractice() => emit(const GeneratorPractice(singleCategory: false));
|
||||
|
||||
void setTest() => emit(const GeneratorTest());
|
||||
|
||||
void setSingleCategory(bool singleCategory) => emit(
|
||||
(state as GeneratorPractice).copyWith(singleCategory: singleCategory));
|
||||
|
||||
|
@ -7,49 +7,6 @@ import '../cubit/questions_cubit.dart';
|
||||
import '../models/category.dart';
|
||||
import 'cubit/generator_cubit.dart';
|
||||
|
||||
class GeneratorForm extends StatelessWidget {
|
||||
const GeneratorForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => BlocProvider(
|
||||
create: (context) => GeneratorCubit(),
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Generator vprašanj',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const TabBar(
|
||||
labelColor: Colors.black,
|
||||
labelPadding: EdgeInsets.all(5),
|
||||
tabs: [
|
||||
Text('Vaja'),
|
||||
Text('Preizkus uspeha'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Expanded(
|
||||
child: TabBarView(
|
||||
children: [
|
||||
PracticeTab(),
|
||||
TestTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class PracticeTab extends StatelessWidget {
|
||||
const PracticeTab({Key? key}) : super(key: key);
|
||||
|
||||
@ -94,7 +51,6 @@ class _CategoryOnlyInput extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text('Generiraj vprašanja le iz določenega področja:'),
|
||||
const SizedBox(width: 10),
|
||||
BlocBuilder<GeneratorCubit, GeneratorState>(
|
||||
buildWhen: (previous, current) {
|
||||
previous as GeneratorPractice;
|
||||
|
@ -3,19 +3,83 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:s5_practice/src/cubit/questions_cubit.dart';
|
||||
import 'package:s5_practice/src/generator/generator_form.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
import 'generator/cubit/generator_cubit.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static const _tabs = [
|
||||
Text('Vaja'),
|
||||
Text('Preizkus uspeha'),
|
||||
];
|
||||
|
||||
late final TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: _tabs.length, vsync: this);
|
||||
_tabController.addListener(() {
|
||||
final gCubit = context.read<GeneratorCubit>();
|
||||
switch (_tabController.index) {
|
||||
case 0:
|
||||
gCubit.setPractice();
|
||||
break;
|
||||
case 1:
|
||||
gCubit.setTest();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('Izpitna vprašanja za radioamaterje')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: BlocBuilder<QuestionsCubit, QuestionsState>(
|
||||
builder: (context, state) => state is! QuestionsLoaded
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: const GeneratorForm(),
|
||||
appBar: AppBar(
|
||||
title: const Text('Izpitna vprašanja za radioamaterje'),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
labelPadding: const EdgeInsets.all(10),
|
||||
tabs: _tabs,
|
||||
),
|
||||
),
|
||||
body: BlocBuilder<QuestionsCubit, QuestionsState>(
|
||||
builder: (context, state) => state is! QuestionsLoaded
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: BlocProvider(
|
||||
create: (context) => GeneratorCubit(),
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
const PracticeTab(),
|
||||
const TestTab(),
|
||||
]
|
||||
.map(
|
||||
(e) => SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: e,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -35,7 +35,5 @@ class QuizCubit extends Cubit<QuizState> {
|
||||
emit(state.copyWith(answers: answers));
|
||||
}
|
||||
|
||||
void extend() => emit(state.copyWith(
|
||||
count: min(state.count + state.firstCount, state.questions.length),
|
||||
));
|
||||
void extend() => emit(state.copyWith(count: state.count + state.firstCount));
|
||||
}
|
||||
|
@ -12,17 +12,18 @@ class QuizState extends Equatable {
|
||||
final List<int?>? answers;
|
||||
final List<Set<int>?>? revealed;
|
||||
|
||||
const QuizState({
|
||||
QuizState({
|
||||
required this.title,
|
||||
required this.questions,
|
||||
int? firstCount,
|
||||
required this.count,
|
||||
required int count,
|
||||
this.duration,
|
||||
required this.revealInstantly,
|
||||
this.startTime,
|
||||
this.answers,
|
||||
this.revealed,
|
||||
}) : firstCount = firstCount ?? count;
|
||||
}) : firstCount = firstCount ?? min(count, questions.length),
|
||||
count = min(count, questions.length);
|
||||
|
||||
QuizState copyWith({
|
||||
String? title,
|
||||
|
Loading…
x
Reference in New Issue
Block a user