Skip to content

Instantly share code, notes, and snippets.

@satishsoni777
Created August 28, 2019 10:53
Show Gist options
  • Save satishsoni777/0e16f3a9a654e5c5b62f5372689c24a2 to your computer and use it in GitHub Desktop.
Save satishsoni777/0e16f3a9a654e5c5b62f5372689c24a2 to your computer and use it in GitHub Desktop.
if text is containing a url then it will show a web view other wise a normal text screen.
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
class TextScreen extends StatefulWidget {
final VoidCallback onClose;
String text;
TextScreen(String text, {this.onClose}) : super() {
this.text = text;
}
@override
_TextScreenState createState() => _TextScreenState();
}
class _TextScreenState extends State<TextScreen> {
bool isContainHttp = false;
@override
void initState() {
if (widget.text.contains('http') || widget.text.contains('https'))
setState(() {
isContainHttp = true;
});
super.initState();
}
@override
Widget build(BuildContext context) {
if (isContainHttp)
return Scaffold(
appBar: AppBar(),
body: Center(
child: WebView(
widget.text,
aspectRatio: MediaQuery.of(context).size.width /
MediaQuery.of(context).size.height,
),
),
);
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.close),
onPressed: () {
widget.onClose();
},
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.grey,
height: 70,
width: 70,
child: Center(child: Text('T', style: TextStyle(fontSize: 40))),
),
SizedBox(
height: 20,
),
Container(color: Colors.grey, child: Text(widget.text))
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment