docx_file_viewer 0.0.7 copy "docx_file_viewer: ^0.0.7" to clipboard
docx_file_viewer: ^0.0.7 copied to clipboard

A Flutter package to view DOCX files within your app. It allows users to load and display DOCX content. While the package tries to render documents accurately, some rendering issues may occur, especia [...]

example/lib/main.dart

import 'dart:io';

import 'package:docx_file_viewer/docx_file_viewer.dart';
import 'package:file_picker/file_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Docx Viewer'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  File? selectedFile;
  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: selectedFile == null
          ? const Center(
              child: Text("Select File"),
            )
          : DocxViewer(
              file: selectedFile!,
            ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          final file = await FilePicker.platform.pickFiles();
          if (file == null) {
            return;
          }
          final filepath = file.files.first.path!;
          // final filebytes = await File(filepath).readAsBytes();

          // log(text.trim());
          setState(() {
            selectedFile = File(filepath);
          });
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
4
likes
140
points
462
downloads
screenshot

Publisher

verified publisheralihassan143cool.blogspot.com

Weekly Downloads

A Flutter package to view DOCX files within your app. It allows users to load and display DOCX content. While the package tries to render documents accurately, some rendering issues may occur, especially with complex formatting.

Repository (GitHub)
View/report issues

Topics

#docx #docxviewer #word

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

archive, flutter, xml

More

Packages that depend on docx_file_viewer