67 lines
2 KiB
Dart
67 lines
2 KiB
Dart
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:gophershy/gopherlib.dart';
|
||
|
|
||
|
/// Basic Gopher plaintext widget
|
||
|
/// Should be able to display ASCII ART
|
||
|
// TODO: separate ASCIIArtTextWidget and PlainTextWidget
|
||
|
// First will scroll horizontlay, preserving formating,
|
||
|
// Second will wrap lines to make it more readable on phones
|
||
|
// TODO: Somehow add option to re-render plaintext as menu view
|
||
|
class GopherText extends StatelessWidget {
|
||
|
|
||
|
final LoadedGopherItem item;
|
||
|
|
||
|
const GopherText(this.item, {super.key});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
// TODO: Figure out how to stop line wrap
|
||
|
// TODO: figure out how to switch between line wrap and no wrap
|
||
|
return ListView.builder(
|
||
|
itemCount: item.data?.length,
|
||
|
itemBuilder: (context, int n) {
|
||
|
return Text(
|
||
|
utf8.decode(item.data![n], allowMalformed: true),
|
||
|
style: const TextStyle(
|
||
|
fontFamily: "SourceCodePro",
|
||
|
fontWeight: FontWeight.w400,
|
||
|
height: 1.0,
|
||
|
// Might need to be tuned for ASCII art
|
||
|
letterSpacing: 1,
|
||
|
wordSpacing: 1,
|
||
|
overflow: TextOverflow.clip
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//TODO: BinaryWidget with option of downloading it
|
||
|
//TODO: MediaWidget with option for displaying images, maybe playing WAVs?
|
||
|
|
||
|
/// Shows listing of gopher directory
|
||
|
class GopherDirectory extends StatelessWidget {
|
||
|
|
||
|
final LoadedGopherItem parsedDirectory;
|
||
|
final Function(ParsedGopherItem clickedOn) onItemClick;
|
||
|
|
||
|
const GopherDirectory({super.key, required this.parsedDirectory, required this.onItemClick});
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return ListView.builder(
|
||
|
itemCount: parsedDirectory.asMenu!.length,
|
||
|
itemBuilder: (context, int n) {
|
||
|
final item = parsedDirectory.asMenu![n];
|
||
|
return GestureDetector(
|
||
|
onTap: () => item.documentType == DocumentType.Informational ? null : onItemClick(item),
|
||
|
child: Text(item.name ?? "err"));
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|