Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support null safety and fix cannot get twitter open graph tags #25

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ linter:
- slash_for_doc_comments
- sort_child_properties_last
# - sort_constructors_first
- sort_pub_dependencies
# - sort_pub_dependencies
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
Expand Down
33 changes: 24 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
const MyHomePage({Key? key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
TextEditingController _controller;
late TextEditingController _controller;
int _index = -1;
final List<String> _urls = [
"https://news.google.com/__i/rss/rd/articles/CBMiMGh0dHBzOi8vd3d3Lm1pcnJvcm1lZGlhLm1nL3N0b3J5LzIwMjExMjE1ZWRpMDExL9IBAA?oc=5",
"https://news.google.com/__i/rss/rd/articles/CBMiOmh0dHBzOi8vbmV3cy5sdG4uY29tLnR3L25ld3MvcG9saXRpY3MvYnJlYWtpbmduZXdzLzM3NjkxNTnSAT5odHRwczovL25ld3MubHRuLmNvbS50dy9hbXAvbmV3cy9wb2xpdGljcy9icmVha2luZ25ld3MvMzc2OTE1OQ?oc=5",
"https://lihkg.com/thread/2529600/page/1",
"https://youtu.be/v_hR4K4auoQ",
"https://twitter.com/sspai_com/status/1392794070704066566?s=20",
"https://mp.weixin.qq.com/s/qj7gkU-Pbdcdn3zO6ZQxqg",
"https://mp.weixin.qq.com/s/43GznPLxi5i3yOdvrlr1JQ",
"https://m.tb.cn/h.VFcZsnK?sm=34cd13",
Expand Down Expand Up @@ -69,11 +74,20 @@ class _MyHomePageState extends State<MyHomePage> {
"https://bbs.hupu.com/36997146.html",
"https://music.163.com/#/playlist?id=4944751157",
];

@override
void initState() {
_controller = TextEditingController(
text:
"https://www.bilibili.com/video/BV1F64y1c7hd?spm_id_from=333.851.b_7265706f7274466972737431.12");

// test useMultithread
WebAnalyzer.getInfo(
_urls[1],
multimedia: false,
useMultithread: true,
).then(print);

super.initState();
}

Expand Down Expand Up @@ -140,15 +154,16 @@ class _MyHomePageState extends State<MyHomePage> {
url: _controller.value.text,
builder: (info) {
if (info == null) return const SizedBox();
if (info is WebImageInfo) {
if (info is WebImageInfo && WebAnalyzer.isNotEmpty(info.image)) {
return CachedNetworkImage(
imageUrl: info.image,
imageUrl: info.image!,
fit: BoxFit.contain,
);
}

final WebInfo webInfo = info;
if (!WebAnalyzer.isNotEmpty(webInfo.title)) return const SizedBox();
final WebInfo? webInfo = info as WebInfo;
if (webInfo == null || !WebAnalyzer.isNotEmpty(webInfo.title))
return const SizedBox();
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
Expand Down Expand Up @@ -177,7 +192,7 @@ class _MyHomePageState extends State<MyHomePage> {
const SizedBox(width: 8),
Expanded(
child: Text(
webInfo.title,
webInfo.title ?? "",
overflow: TextOverflow.ellipsis,
),
),
Expand All @@ -186,15 +201,15 @@ class _MyHomePageState extends State<MyHomePage> {
if (WebAnalyzer.isNotEmpty(webInfo.description)) ...[
const SizedBox(height: 8),
Text(
webInfo.description,
webInfo.description ?? "",
maxLines: 5,
overflow: TextOverflow.ellipsis,
),
],
if (WebAnalyzer.isNotEmpty(webInfo.image)) ...[
const SizedBox(height: 8),
CachedNetworkImage(
imageUrl: webInfo.image,
imageUrl: webInfo.image!,
fit: BoxFit.contain,
),
]
Expand Down
Loading