import 'dart:io';

import 'package:flutter/material.dart';
import 'package:easy_pdf_viewer/easy_pdf_viewer.dart';
import 'package:flutter_text_viewer/model/text_viewer.dart';
import 'package:flutter_text_viewer/screen/text_viewer_page.dart';
import 'package:initial_folder/size_config.dart';
import 'package:initial_folder/theme.dart';

class txtReader extends StatefulWidget {
  final String link;
  // final String title;
  const txtReader({Key? key, required this.link});

  @override
  State<txtReader> createState() => _txtReaderState();
}

class _txtReaderState extends State<txtReader> {
  @override
  void initState() {
    super.initState();
    print(widget.link);
  }

  @override
  void dispose() {
    super.dispose();
    // Hapus file .txt saat widget di-dispose
    File(widget.link).deleteSync(recursive: true);
  }

  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: TextViewerPage(
      textViewer: TextViewer.asset(
        widget.link,
        highLightColor: Colors.yellow,
        focusColor: Colors.orange,
        ignoreCase: true,
      ),
      showSearchAppBar: true,
    )));
  }
}
