Skip to content

Commit eb4866f

Browse files
authored
Update document_viewer_screen.dart [build]
1 parent 9fbc265 commit eb4866f

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed
Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'dart:convert'; // Za jsonEncode/jsonDecode
1+
import 'dart:convert';
22
import 'package:flutter/material.dart';
33
import 'package:fleather/fleather.dart';
44
import 'package:parchment/parchment.dart';
@@ -16,14 +16,13 @@ class _DocumentViewerScreenState extends State<DocumentViewerScreen> {
1616
FleatherController? _controller;
1717
late Box _box;
1818
final String _defaultDocName = "novo_pisanje";
19+
final FocusNode _focusNode = FocusNode();
1920

2021
@override
2122
void initState() {
2223
super.initState();
2324
_box = Hive.box('documents_box');
2425
_loadDocument();
25-
26-
// Auto-save: Svaki put kad se tekst promeni, snimi u Hive
2726
_controller!.addListener(_autoSave);
2827
}
2928

@@ -32,47 +31,81 @@ class _DocumentViewerScreenState extends State<DocumentViewerScreen> {
3231
final String? savedData = _box.get(key);
3332

3433
if (savedData != null) {
35-
// Ako imamo sačuvano, učitaj taj Delta JSON
3634
final doc = ParchmentDocument.fromJson(jsonDecode(savedData));
3735
_controller = FleatherController(document: doc);
3836
} else {
39-
// Ako je prazno, kreni od nule
4037
_controller = FleatherController();
4138
}
4239
}
4340

4441
void _autoSave() {
4542
final String key = widget.fileName ?? _defaultDocName;
46-
// Pretvaramo Delta format u JSON string
4743
final deltaData = jsonEncode(_controller!.document.toDelta());
48-
49-
// Upisujemo u Hive
5044
_box.put(key, deltaData);
51-
// Print u konzolu samo da vidiš da radi dok testiraš
5245
debugPrint("Dokument sačuvan: ${DateTime.now()}");
5346
}
5447

5548
@override
5649
Widget build(BuildContext context) {
50+
// Proveravamo da li je tastatura otvorena
51+
final bool isKeyboardVisible = MediaQuery.of(context).viewInsets.bottom > 0;
52+
5753
return Scaffold(
5854
appBar: AppBar(
5955
title: Text(
6056
widget.fileName ?? 'f.Sentence',
61-
style: const TextStyle(fontWeight: FontWeight.w300), // Tvoj tanak stil
57+
style: const TextStyle(fontWeight: FontWeight.w300),
6258
),
6359
),
64-
body: Column(
60+
body: Stack(
6561
children: [
66-
FleatherToolbar.basic(controller: _controller!),
67-
Expanded(
68-
child: Container(
69-
padding: const EdgeInsets.all(16),
70-
child: FleatherEditor(
71-
controller: _controller!,
72-
padding: EdgeInsets.zero,
62+
Column(
63+
children: [
64+
Expanded(
65+
child: Padding(
66+
padding: const EdgeInsets.symmetric(horizontal: 16),
67+
child: FleatherEditor(
68+
controller: _controller!,
69+
focusNode: _focusNode,
70+
padding: const EdgeInsets.only(bottom: 100), // Da tekst ne ide ispod pilule
71+
),
72+
),
7373
),
74-
),
74+
],
7575
),
76+
77+
// Pilula toolbar
78+
if (isKeyboardVisible)
79+
Positioned(
80+
bottom: MediaQuery.of(context).viewInsets.bottom + 10,
81+
left: 20,
82+
right: 20,
83+
child: Material(
84+
elevation: 4,
85+
borderRadius: BorderRadius.circular(30),
86+
color: Theme.of(context).colorScheme.surfaceContainerHighest,
87+
child: Container(
88+
height: 50,
89+
padding: const EdgeInsets.symmetric(horizontal: 10),
90+
child: Theme(
91+
data: Theme.of(context).copyWith(
92+
// Smanjujemo ikone da bi stale u tanku pilulu
93+
iconTheme: const IconThemeData(size: 20),
94+
),
95+
child: SingleChildScrollView(
96+
scrollDirection: Axis.horizontal,
97+
child: FleatherToolbar.basic(
98+
controller: _controller!,
99+
// Isključujemo nepotrebne stvari za čistiji izgled
100+
hideHeadingSelection: false,
101+
hideIndentation: true,
102+
hideListNumbers: true,
103+
),
104+
),
105+
),
106+
),
107+
),
108+
),
76109
],
77110
),
78111
);
@@ -82,6 +115,7 @@ class _DocumentViewerScreenState extends State<DocumentViewerScreen> {
82115
void dispose() {
83116
_controller?.removeListener(_autoSave);
84117
_controller?.dispose();
118+
_focusNode.dispose();
85119
super.dispose();
86120
}
87121
}

0 commit comments

Comments
 (0)