lundi 22 mars 2021

I'd like to have https:// automatically attached to the link

When I tried to retrieve img from the website, the link started with /upload/.... instead of https://.

I want to have https:// written automatically in front of me. What should I do?

homepage:

<div class="photo_list">
    <ul>
        <li>
            <a href="/yongwon-h/na/ntt/selectNttInfo.do?nttSn=85189591&amp;mi=73747">

                <img src="/upload/bbs/files/2021/hgschl/yongwon-h/ntt/62865/ntt_85189591/thumb/thumb_img_9028b523-7bfb-466f-848c-65870a93b99c1616411595463.jpg" onerror="this.src='/images/co/na/noImg.gif'" alt="대표이미지">
                                                            
                <p>책을 가까이, 책은 나의 친구!! 아침독서의 생활화!!!</p>
                <span>
                                                
                    2021.03.22
                    <br> 조회   6
                </span>
                
            </a>
        </li>
    </ul>
</div>

MY CODE:

import 'package:flutter/material.dart';
import 'package:flutter_share/flutter_share.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:http/http.dart' as http;
import 'package:html/dom.dart' as dom;
import 'package:html/parser.dart' as parser;
import 'package:url_launcher/url_launcher.dart';

class UpdatePost extends StatefulWidget {
  @override
  _UpdatePostState createState() => _UpdatePostState();
}

class _UpdatePostState extends State<UpdatePost> {
  List<String> title = List();
  List<String> post = List();
  List<String> link = List();

  List<String> image = List();

  void _getDataFromWeb() async {
    Uri uri = Uri.parse(
        'http://yongwon-h.gne.go.kr/yongwon-h/na/ntt/selectNttList.do?mi=73747&&bbsId=62865');
    final response = await http.get(uri);
    dom.Document document = parser.parse(response.body);
    final link2 = document.getElementsByClassName('photo_list');
    final content = document.getElementsByClassName('photo_list');
    final elements = document.getElementsByClassName('photo_list');

    final ImageElement = document.getElementsByClassName('photo_list');
    setState(() {
      title = elements
          .map((element) => element.getElementsByTagName("p")[0].innerHtml)
          .toList();
      post = content
          .map((element) => element.getElementsByTagName("span")[0].innerHtml)
          .toList();
      link = link2
          .map((element) =>
              element.getElementsByTagName("a")[0].attributes['href'])
          .toList();

      image = ImageElement.map((element) =>
          element.getElementsByTagName("img")[0].attributes['src']).toList();
    });
  }

  Future<void> share(dynamic link, String title) async {
    await FlutterShare.share(
        title: 'Codding Application',
        text: title,
        linkUrl: link,
        chooserTitle: 'Where You Want to Share');
  }

  @override
  void initState() {
    _getDataFromWeb();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black87,
      body: post.length == 0
          ? Text("No data", style: TextStyle(color: Colors.white))
          : ListView.builder(
              itemCount: post.length,
              itemBuilder: (context, index) {
                return AnimationConfiguration.staggeredList(
                  position: index,
                  duration: const Duration(milliseconds: 375),
                  child: SlideAnimation(
                      child: FadeInAnimation(
                          child: GestureDetector(
                    onTap: () async {
                      dynamic url = link[index];
                      if (await canLaunch(url))
                        launch(url);
                      else {
                        print('error');
                      }
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(10),
                      child: Card(
                        child: Container(
                          color: Colors.black87,
                          child: Column(
                            children: <Widget>[
                              Container(
                                child: Image.network(
                                  image[index],
                                  scale: 0.1,
                                ),
                              ),
                              Align(
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  title[index],
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Colors.red,
                                    fontSize: 20,
                                  ),
                                ),
                              ),
                              SizedBox(height: 15),
                              Text(
                                post[index],
                                style: TextStyle(
                                  color: Colors.white,
                                ),
                              ),
                              Row(
                                children: <Widget>[
                                  FlatButton(
                                    shape: RoundedRectangleBorder(
                                        borderRadius:
                                            BorderRadius.circular(5.0),
                                        side: BorderSide(color: Colors.white)),
                                    onPressed: () {
                                      share(link[index], title[index]);
                                    },
                                    child: Text(
                                      "Share With Friends",
                                      style: TextStyle(
                                        color: Colors.red,
                                      ),
                                    ),
                                  ),
                                  SizedBox(width: 10),
                                  FlatButton(
                                    shape: RoundedRectangleBorder(
                                        borderRadius:
                                            BorderRadius.circular(5.0),
                                        side: BorderSide(color: Colors.white)),
                                    onPressed: () async {
                                      dynamic url = link[index];
                                      if (await canLaunch(url))
                                        launch(url);
                                      else {
                                        print('error');
                                      }
                                    },
                                    child: Text(
                                      "Explore Post",
                                      style: TextStyle(
                                        color: Colors.red,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ))),
                );
              },
            ),
    );
  }
}

conclusion: I want to automatically put http://yongwon-h.gne.go.kr in front of the called tag a.

I feel like I'm asking repeatedly, but I really don't know. I googled thousands of sites in a week. Please help me.




Aucun commentaire:

Enregistrer un commentaire