manager-app/lib/Screens/Policy/policy_screen.dart
2024-07-09 12:40:38 +02:00

89 lines
2.9 KiB
Dart

import 'dart:html' as html;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:manager_app/Components/loading_common.dart';
import 'package:manager_app/app_context.dart';
import 'package:provider/provider.dart';
class PolicyScreen extends StatefulWidget {
final String? param;
PolicyScreen({this.param});
@override
_PolicyScreenState createState() => _PolicyScreenState();
}
class _PolicyScreenState extends State<PolicyScreen> {
final html.IFrameElement _iframeElement = html.IFrameElement();
String filePath2 = 'assets/files/policy_page.html';
String filePath = 'assets/files/policy_text.text';
String filePathMDLF = 'assets/files/policy_text_mdlf.text';
String filePathFort = 'assets/files/policy_text_fort.text';
@override
Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
return Scaffold(
body: FutureBuilder(
future: getHTML(),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Container(
width: size.width * 0.9,
height: size.height,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Center(child: Text(snapshot.data)),
],
),
),
)
/*child: WebView(htmlText: snapshot.data))*/
);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(
child: Container(
height: size.height * 0.2,
child: LoadingCommon()
)
);
}
}
));
}
_loadHtmlFromAssets() async {
String fileHtmlContents = await rootBundle.loadString(filePath);
/*if(kIsWeb) {
_iframeElement.src = fileHtmlContents;
_iframeElement.style.border = 'none';
//ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
_loadHtmlFromAssets(), //use source as registered key to ensure uniqueness
(int viewId) => _iframeElement,
);
}*/
return fileHtmlContents;
}
Future<String> getHTML() async {
switch(widget.param) {
case "mdlf":
return await rootBundle.loadString(filePathMDLF);
case "fort":
return await rootBundle.loadString(filePathFort);
}
return await rootBundle.loadString(filePath);
}
}