diff --git a/lib/SonicEmailViewAndroid.dart b/lib/SonicEmailViewAndroid.dart new file mode 100644 index 0000000..fc2b67c --- /dev/null +++ b/lib/SonicEmailViewAndroid.dart @@ -0,0 +1,19 @@ +import 'structs.dart'; +import 'package:flutter/material.dart'; + +class SonicEmailView extends StatefulWidget { + SerializableMessage email; + String emailHTML; + + SonicEmailView({required this.email, required this.emailHTML}); + + @override + _SonicEmailViewState createState() => _SonicEmailViewState(); +} + +class _SonicEmailViewState extends State { + @override + Widget build(BuildContext context) { + return Scaffold(body: Text("sonic email android")); + } +} diff --git a/lib/SonicEmailViewStub.dart b/lib/SonicEmailViewStub.dart new file mode 100644 index 0000000..0307a15 --- /dev/null +++ b/lib/SonicEmailViewStub.dart @@ -0,0 +1,22 @@ +import 'structs.dart'; +import 'package:flutter/material.dart'; + +class SonicEmailView extends StatefulWidget { + SerializableMessage email; + String emailHTML; + + SonicEmailView({required this.email, required this.emailHTML}); + + @override + _SonicEmailViewState createState() => _SonicEmailViewState(); +} + +class _SonicEmailViewState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + body:Text("sonic email stub") + ); + } + +} diff --git a/lib/SonicEmailViewWeb.dart b/lib/SonicEmailViewWeb.dart new file mode 100644 index 0000000..3ad8f76 --- /dev/null +++ b/lib/SonicEmailViewWeb.dart @@ -0,0 +1,145 @@ +import 'package:crab_ui/augment.dart'; +import 'package:web/web.dart' as web; +import 'dart:ui_web' as ui; +import 'dart:js_interop'; +import 'structs.dart'; +import 'package:flutter/material.dart'; + +class SonicEmailView extends StatefulWidget { + SerializableMessage email; + String emailHTML; + + SonicEmailView({required this.email, required this.emailHTML}); + + @override + _SonicEmailViewState createState() => _SonicEmailViewState(); +} + +class _SonicEmailViewState extends State { + String viewTypeIDs = ""; + int heightOFViewtype = 0; + bool _isLoaded = false; + + void _scrollToNumber(String spanId) { + AugmentClasses.handleJump(spanId); + } + + @override + void initState() { + super.initState(); + _init(); + } + + Future _init() async { + await _registerViewFactory(widget.emailHTML); + if (!mounted) return; + setState(() { + _isLoaded = true; + }); + } + + Future _registerViewFactory(String currentContent) async { + // setState(() { //update to do item per item + // each item to have itsviewtype ID + // is this necessarey here?? + + //could just move to collapsable + + // for (var emailHTML in widget.threadHTML) { + String viewTypeId = 'email-${DateTime.now().millisecondsSinceEpoch}'; + + final ghost = web.document.createElement('div') as web.HTMLDivElement + ..style.visibility = 'hidden' + ..style.position = 'absolute' + ..style.width = '100%' + ..style.overflow = 'auto' + ..innerHTML = currentContent.toJS; + web.document.body?.append(ghost); + await Future.delayed(Duration(milliseconds: 10)); + + final heightOfEmail = ghost.scrollHeight; + ghost.remove(); + + final HTMLsnippet = web.document.createElement('div') as web.HTMLDivElement + ..id = viewTypeId + ..innerHTML = widget + .emailHTML.toJS; // temporarily index because it has to do all of them + HTMLsnippet.style + ..width = '100%' + ..height = '${heightOfEmail}px' + ..overflow = 'auto' + ..scrollBehavior = 'smooth'; + + ui.platformViewRegistry.registerViewFactory( + viewTypeId, + (int viewId) => HTMLsnippet, + ); + this.viewTypeIDs = viewTypeId; + this.heightOFViewtype = heightOfEmail; + print(viewTypeIDs); + } + + @override + Widget build(BuildContext context) { + return _isLoaded + ? Scaffold( + appBar: AppBar(title: Text(widget.email.subject)), + body: Stack( + children: [ + Column( + children: [ + EmailToolbar( + onButtonPressed: () => {}, + onJumpToSpan: _scrollToNumber), + Row( + // title of email + children: [ + Text( + widget.email.subject, + style: TextStyle(fontSize: 30), + ), + ], + ), + Row( + children: [ + Text( + 'from ${widget.email.name}', + style: TextStyle(fontSize: 18), + ), + Text( + '<${widget.email.from}>', + style: TextStyle(fontSize: 18), + ), + Spacer(), + Text( + '${widget.email.date}', + textAlign: TextAlign.right, + ) + ], + ), + // TODO: make a case where if one of these is the user's email it just says me :))))) + Row( + children: [ + Text( + 'to ${widget.email.to.toString()}', + style: TextStyle(fontSize: 15), + ) + ], + ), + Expanded( + // child: SizedBox( + // height: heightOFViewtype.toDouble(), + child: HtmlElementView( + key: UniqueKey(), viewType: this.viewTypeIDs, + // ), + )) + ], + ), + ], + ), + ) + : const Center( + child: CircularProgressIndicator(), + ); + } +} diff --git a/lib/sonicEmailView.dart b/lib/sonicEmailView.dart index bfe0bbe..aeb7301 100644 --- a/lib/sonicEmailView.dart +++ b/lib/sonicEmailView.dart @@ -1,145 +1,3 @@ -import 'package:crab_ui/augment.dart'; -import 'package:web/web.dart' as web; -import 'dart:ui_web' as ui; -import 'dart:js_interop'; -import 'structs.dart'; -import 'package:flutter/material.dart'; - -class SonicEmailView extends StatefulWidget { - SerializableMessage email; - String emailHTML; - - SonicEmailView({required this.email, required this.emailHTML}); - - @override - _SonicEmailViewState createState() => _SonicEmailViewState(); -} - -class _SonicEmailViewState extends State { - String viewTypeIDs = ""; - int heightOFViewtype = 0; - bool _isLoaded = false; - - void _scrollToNumber(String spanId) { - AugmentClasses.handleJump(spanId); - } - - @override - void initState() { - super.initState(); - _init(); - } - - Future _init() async { - await _registerViewFactory(widget.emailHTML); - if (!mounted) return; - setState(() { - _isLoaded = true; - }); - } - - Future _registerViewFactory(String currentContent) async { - // setState(() { //update to do item per item - // each item to have itsviewtype ID - // is this necessarey here?? - - //could just move to collapsable - - // for (var emailHTML in widget.threadHTML) { - String viewTypeId = 'email-${DateTime.now().millisecondsSinceEpoch}'; - - final ghost = web.document.createElement('div') as web.HTMLDivElement - ..style.visibility = 'hidden' - ..style.position = 'absolute' - ..style.width = '100%' - ..style.overflow = 'auto' - ..innerHTML = currentContent.toJS; - web.document.body?.append(ghost); - await Future.delayed(Duration(milliseconds: 10)); - - final heightOfEmail = ghost.scrollHeight; - ghost.remove(); - - final HTMLsnippet = web.document.createElement('div') as web.HTMLDivElement - ..id = viewTypeId - ..innerHTML = widget - .emailHTML.toJS; // temporarily index because it has to do all of them - HTMLsnippet.style - ..width = '100%' - ..height = '${heightOfEmail}px' - ..overflow = 'auto' - ..scrollBehavior = 'smooth'; - - ui.platformViewRegistry.registerViewFactory( - viewTypeId, - (int viewId) => HTMLsnippet, - ); - this.viewTypeIDs = viewTypeId; - this.heightOFViewtype = heightOfEmail; - print(viewTypeIDs); - } - - @override - Widget build(BuildContext context) { - return _isLoaded - ? Scaffold( - appBar: AppBar(title: Text(widget.email.subject)), - body: Stack( - children: [ - Column( - children: [ - EmailToolbar( - onButtonPressed: () => {}, - onJumpToSpan: _scrollToNumber), - Row( - // title of email - children: [ - Text( - widget.email.subject, - style: TextStyle(fontSize: 30), - ), - ], - ), - Row( - children: [ - Text( - 'from ${widget.email.name}', - style: TextStyle(fontSize: 18), - ), - Text( - '<${widget.email.from}>', - style: TextStyle(fontSize: 18), - ), - Spacer(), - Text( - '${widget.email.date}', - textAlign: TextAlign.right, - ) - ], - ), - // TODO: make a case where if one of these is the user's email it just says me :))))) - Row( - children: [ - Text( - 'to ${widget.email.to.toString()}', - style: TextStyle(fontSize: 15), - ) - ], - ), - Expanded( - // child: SizedBox( - // height: heightOFViewtype.toDouble(), - child: HtmlElementView( - key: UniqueKey(), viewType: this.viewTypeIDs, - // ), - )) - ], - ), - ], - ), - ) - : const Center( - child: CircularProgressIndicator(), - ); - } -} +export 'SonicEmailViewStub.dart' + if (dart.library.js_interop) 'SonicEmailViewWeb.dart' + if (dart.library.io) 'SonicEmailViewAndroid.dart'; \ No newline at end of file