• About
  • Advertise
  • Privacy & Policy
  • Contact
Tech News, Magazine & Review WordPress Theme 2017
  • ACCUEIL
    • Home – Layout 5
  • Review

    National Academy of Sciences endorses embryonic engineering

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Fujifilm X-T2 review: The definition of a great camera

    The Analogue Nt Mini is the perfect NES console for video game lovers

    Using a mind reading device, ‘locked-in’ patients told researchers they’re happy

    Watch Cruise’s self-driving Bolt EV navigate smoothly to SF’s Dolores Park

  • Gaming

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    The Analogue Nt Mini is the perfect NES console for video game lovers

    GoPro’s Karma drone is back on sale after design flaw made them fall out of the sky

  • Gear
    • All
    • Audio
    • Camera
    • Laptop
    • Smartphone

    Apple Watch Series 2 Is Swimproof and Comes With Built-In GPS

    National Academy of Sciences endorses embryonic engineering

    Jack Dorsey says he’ll continue running both Square and Twitter

    Fujifilm X-T2 review: The definition of a great camera

    The Warby Parker of hair color, Madison Reed, scores new funding and a CMO

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Fujifilm X-T2 review: The definition of a great camera

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

    SpaceX targets February 18 for Dragon resupply mission to ISS

  • Applications

    Apple Watch Series 2 Is Swimproof and Comes With Built-In GPS

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Jack Dorsey says he’ll continue running both Square and Twitter

  • Security

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    The Warby Parker of hair color, Madison Reed, scores new funding and a CMO

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

No Result
View All Result
  • ACCUEIL
    • Home – Layout 5
  • Review

    National Academy of Sciences endorses embryonic engineering

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Fujifilm X-T2 review: The definition of a great camera

    The Analogue Nt Mini is the perfect NES console for video game lovers

    Using a mind reading device, ‘locked-in’ patients told researchers they’re happy

    Watch Cruise’s self-driving Bolt EV navigate smoothly to SF’s Dolores Park

  • Gaming

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    The Analogue Nt Mini is the perfect NES console for video game lovers

    GoPro’s Karma drone is back on sale after design flaw made them fall out of the sky

  • Gear
    • All
    • Audio
    • Camera
    • Laptop
    • Smartphone

    Apple Watch Series 2 Is Swimproof and Comes With Built-In GPS

    National Academy of Sciences endorses embryonic engineering

    Jack Dorsey says he’ll continue running both Square and Twitter

    Fujifilm X-T2 review: The definition of a great camera

    The Warby Parker of hair color, Madison Reed, scores new funding and a CMO

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

    Trending Tags

    • Best iPhone 7 deals
    • Apple Watch 2
    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • iOS 10
    • iPhone 7
    • Sillicon Valley
  • Computers

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Fujifilm X-T2 review: The definition of a great camera

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

    SpaceX targets February 18 for Dragon resupply mission to ISS

  • Applications

    Apple Watch Series 2 Is Swimproof and Comes With Built-In GPS

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    Jack Dorsey says he’ll continue running both Square and Twitter

  • Security

    To regain advertiser trust, Facebook is tracking ads by the millisecond

    National Academy of Sciences endorses embryonic engineering

    Google has been asked to take down over a million websites

    Watch Dogs 2 Update Coming This Week, Here’s What It Does

    The Warby Parker of hair color, Madison Reed, scores new funding and a CMO

    Shopify CEO attempts to defend continued hosting of Breitbart’s online store

No Result
View All Result
Technique de pointe
No Result
View All Result
Home Générale

7 étapes pour créer une application Android et IOS pour votre blog WordPress via Flutter

Caleb by Caleb
mai 23, 2021
168
7 étapes pour créer une application Android et IOS pour votre blog WordPress via Flutter
Share on FacebookShare on Twitter


Photo de profil de FlutterNerd Hacker Noon

@flutternerdFlutterNerd

Chez FlutterNerd by Sanskar Tiwari, vous pouvez apprendre et maîtriser le développement d’applications de flutter en créant des applications du monde réel.

Je voulais donc créer une application pour notre site Web et bien, il s’est avéré que c’était plus facile que je ne le pensais.

Alors, commençons

Étape 1: Télécharger et activer le plugin pour le blog WordPress

Relier: https://wordpress.org/plugins/easily-generate-rest-api-url/

Étape 2: Dans le tableau de bord WordPress

Allez dans les paramètres (survolez-le)> (Cliquez sur) Générer l’URL de l’API Rest, faites défiler vers le bas, vous aurez une URL d’API. Vous pouvez le modifier si vous le souhaitez.

Étape 3: Créer un projet Flutter

Si vous ne l’avez pas déjà fait, installez et configurez Flutter à partir de flutter.dev

J’ai utilisé vs code mais vous pouvez également utiliser Android Studio. Cela fonctionnera de la même manière.

Étape 4: Créer des fonctions pour récupérer les articles et l’URL de l’image des articles

Créez un fichier nommé wp-api.dart puis ajoutez package http, et ajoutez cette fonction:

Future<List> fetchWpPosts() async {
  final response = await http.get(
      "https://flutternerd.com/index.php/wp-json/wp/v2/posts",
      headers: {"Accept": "application/json"});
  var convertDatatoJson = jsonDecode(response.body);
  return convertDatatoJson;
}

Étape 5: Créez un frontend et utilisez cette fonction en important le fichier

import 'package:flutter/material.dart';
import 'package:nativewordpress/views/PostPage.dart';
import 'package:nativewordpress/wp-api.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  String removeAllHtmlTags(String htmlText) {
    RegExp exp = RegExp(r"<[^>]*>", multiLine: true, caseSensitive: true);

    return htmlText.replaceAll(exp, '');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("FlutterNerd"),
      ),
      body: Container(
        padding: EdgeInsets.only(top: 24),
        child: FutureBuilder(
          future: fetchWpPosts(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return ListView.builder(
                  itemCount: snapshot.data.length,
                  itemBuilder: (BuildContext context, int index) {
                    Map wppost = snapshot.data[index];
                    return PostTile(
                        imageApiUrl: wppost['_links']["wp:featuredmedia"][0]
                            ["href"],
                        excerpt: removeAllHtmlTags(wppost['excerpt']['rendered']
                            .replaceAll("&#8217;", "")),
                        desc: wppost['content']['rendered'],
                        title: wppost['title']['rendered']
                            .replaceAll("#038;", ""));
                  });
            }

            return Center(child: CircularProgressIndicator());
          },
        ),
      ),
    );
  }
}

class PostTile extends StatefulWidget {
  final String imageApiUrl, title, desc, excerpt;
  PostTile({this.imageApiUrl, this.title, this.desc, this.excerpt});

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

class _PostTileState extends State<PostTile> {
  String imageUrl = "";

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (imageUrl != "") {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => PostPage(
                        title: widget.title,
                        imageUrl: imageUrl,
                        desc: widget.desc,
                      )));
        }
      },
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            FutureBuilder(
                future: fetchWpPostImageUrl(widget.imageApiUrl),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    imageUrl = snapshot.data["guid"]["rendered"];
                    return Image.network(imageUrl);
                  }
                  return Center(child: CircularProgressIndicator());
                }),
            SizedBox(height: 8),
            Text(
              widget.title,
              style: TextStyle(fontSize: 16),
            ),
            SizedBox(height: 5),
            Text(widget.excerpt)
          ],
        ),
      ),
    );
  }
}

Étape 6: Nous devrons créer une fonction distincte pour obtenir l’url de l’image de chaque message

fetchWpPostImageUrl(url) async {
  final response = await http.get(url, headers: {"Accept": "application/json"});
  var convertDatatoJson = jsonDecode(response.body);
  return convertDatatoJson;
}

Étape 7: Créons maintenant une page de publication

Nous devons ajouter flutter_html_view paquet puis

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

class PostPage extends StatefulWidget {
  final String imageUrl, title, desc;
  PostPage({this.title, this.desc, this.imageUrl});

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

class _PostPageState extends State<PostPage> {
  Widget postContent(htmlContent) {
    return HtmlView(
      data: htmlContent, // optional, type String
      onLaunchFail: (url) {
        // optional, type Function
        print("launch $url failed");
      },
      scrollable: false,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              widget.imageUrl != null
                  ? Image.network(widget.imageUrl)
                  : Container(),
              SizedBox(height: 8),
              Text(
                widget.title,
                style: TextStyle(fontSize: 18),
              ),
              SizedBox(height: 6),
              postContent(
                widget.desc,
              )
            ],
          ),
        ),
      ),
    );
  }
}

C’est ça!

Et c’est ainsi que nous pouvons créer une application Android et iOS pour votre blog WordPress. Si vous rencontrez des problèmes, n’hésitez pas à commenter ci-dessous.

Publié à l’origine à FlutterNerd.com

Photo de profil de FlutterNerd Hacker Noon

Histoires liées

Mots clés

Rejoignez Hacker Noon

Créez votre compte gratuit pour débloquer votre expérience de lecture personnalisée.

— to hackernoon.com

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe
Caleb

Caleb

Recommended.

The Scientific Observer Numéro du 01 avril 2021 EBook

The Scientific Observer Numéro du 01 avril 2021 EBook

avril 23, 2021
Est-ce un jeu vidéo ou un théâtre en ligne ?  Un peu des deux – et beaucoup de plaisir

Est-ce un jeu vidéo ou un théâtre en ligne ? Un peu des deux – et beaucoup de plaisir

octobre 5, 2021

Subscribe.

Trending.

10 problèmes courants de l’iPhone 13 et comment les résoudre

10 problèmes courants de l’iPhone 13 et comment les résoudre

décembre 24, 2021
Comment installer phpMyAdmin sur Debian 11 Bullseye (Apache)

Comment installer phpMyAdmin sur Debian 11 Bullseye (Apache)

novembre 25, 2021
Étapes pour installer MySQL sur Ubuntu 22.04 LTS Jammy Linux

Étapes pour installer MySQL sur Ubuntu 22.04 LTS Jammy Linux

mai 15, 2022
Avantages et inconvénients des concepteurs et créateurs de jeux vidéo

Avantages et inconvénients des concepteurs et créateurs de jeux vidéo

septembre 17, 2021
Comment créer une calculatrice simple à l’aide de HTML, CSS et JavaScript

Comment créer une calculatrice simple à l’aide de HTML, CSS et JavaScript

juin 19, 2022

Catégories de produits

  • Non classé (2)
Technique de pointe

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow Us

Catégories

  • Apple
  • Applications
  • Audio
  • Camera
  • Computers
  • Gaming
  • Gear
  • Générale
  • Laptop
  • Microsoft
  • Photography
  • portrait
  • Review
  • Security
  • Smartphone

Étiquettes

actualités industrielles actualité économique affaires ailette AMERS ASIE ASXPAC BACT Buying Guides CMPNY Commerce courrier quotidien CYCS CYCS08 des sports Divertissement EMRG Entreprise GEN Inc. ITSE ITSE08 jeu vidéo jeux vidéo l'informatique l'Internet La technologie Logiciel Microsoft MTPIX NOM nous nouvelles Playstation 4 Pro politique Sillicon Valley SWIT TECH08 technologie TMT TOPCMB TOPNWS Types de contenu Éducation économie

Recent News

Appelez-moi – Peut-être ? : Le 50e anniversaire du premier appel téléphonique

Appelez-moi – Peut-être ? : Le 50e anniversaire du premier appel téléphonique

mars 31, 2023
Suivi des formulaires avec Google Analytics (via WordPress et GTM)

Suivi des formulaires avec Google Analytics (via WordPress et GTM)

mars 31, 2023
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Accueil
  • high tech
  • Jeu Vidéo
  • Tutoriel
    • HTML5 / CSS
    • Java Script
    • PHP / MySQL
  • Microsoft
  • Apple
  • Review
  • Applications
  • Photography
  • Security

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Sign In with Facebook
Sign In with Google
Sign In with Linked In
OR

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

Nous avons découvert un nouveau système qui génère des revenus 100% passifs... Ignorer