dghub_web_scrapper 1.0.0 copy "dghub_web_scrapper: ^1.0.0" to clipboard
dghub_web_scrapper: ^1.0.0 copied to clipboard

Min Thant Htet.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:dghub_web_scrapper/dghub_web_scrapper.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DG Web Scrapper',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'DG Web Scrapper'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String text = 'Loading...';

  getData() {
    DGHubWebScrapper.get('https://cv.dghub.in').then((value) {
      text = value!.body!
          .getElementsByClassName('about-disc')[0]
          .text
          .trim()
          .toString();

      print(text);
      setState(() {});
    }).onError((error, stackTrace) {
      print(error.toString());
    });
  }

  @override
  void initState() {
    getData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                text,
              ),
            ],
          ),
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}