Justsanesi

Read .txt file

May 8th, 2022 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.29 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import '../textstyle.dart';
  3. import 'dart:async' show Future;
  4. import 'package:flutter/services.dart' show rootBundle;
  5. import '../texts.dart';
  6.  
  7. class AssemblyPage extends StatelessWidget {
  8.  
  9.   // assets\text_files\assembly_description.txt
  10.  
  11.   // loadString() {
  12.   //   var filePath = p.join('/text_files', 'assembly_description.txt');
  13.   //   io.File file = io.File(filePath);
  14.   //   var fileContent = file.readAsStringSync();
  15.   //   return fileContent;
  16.   //   }
  17.  
  18.   // Future<String> readData() async {
  19.   //   String myFile = await io.File('text_files/assembly_description.txt').readAsString(encoding: utf8);
  20.   //   String data = await rootBundle.loadString('text_files/assembly_description.txt');
  21.   //   return myFile;
  22.   // }
  23.  
  24.   Future<String> loadText() async{
  25.     return await rootBundle.loadString('assets/textfiles/assembly_description.txt');
  26.   }
  27.  
  28.   // final text = io.File('text_files/assembly_description.txt').readAsString().toString();
  29.  
  30.   @override
  31.   Widget build(BuildContext context) {
  32.     return Scaffold(
  33.       body: ListView(
  34.         children: [
  35.           Image.asset('assets/images/assieme.png'),
  36.           Container(
  37.           padding: EdgeInsets.all(8),
  38.           child: MediumBlackText(loadText())),
  39.         ],
  40.       ),
  41.     );
  42.   }
  43. }
Add Comment
Please, Sign In to add comment