如何在动态列表视图颤动中添加原生广告

时间:2020-10-26 21:03:00

标签: flutter listview native-ads

我想在列表视图之间添加Facebook Native AD,但是我该怎么做? 我找到了2个有关该主题的教程,但在我的情况下不起作用

这是我的列表视图代码:

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:clipboard_manager/clipboard_manager.dart';
import 'package:social_share/social_share.dart';
import 'package:share/share.dart';

// ignore: must_be_immutable
class ListViewFromApi extends StatefulWidget {
  @override
  _ListViewFromApiState createState() => _ListViewFromApiState();
}

class _ListViewFromApiState extends State<ListViewFromApi> {
  List records;

  Future<void> fetch() async {
    String url =
        "https://api.airtable.com/v0/app1HMb0Up2aZ5IBk/Karbala%20SMS%202020?view=Grid%20view";
    Map<String, String> header = {"Authorization": "Bearer keyVHB9bxOrHrbxIu"};
    http.Response res = await http.get(url, headers: header);
    Map<String, dynamic> result = json.decode(res.body);
    records = result['records'];
    setState(() {});
    return;
  }

  @override
  void initState() {
    Future.microtask(() async => await this.fetch());
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.all(3.0),
        child: records == null
            ? Center(
                child: CircularProgressIndicator(),
              )
            : ListView.builder(
                itemCount: this.records.length,
                itemBuilder: (BuildContext context, int index) {
                  return Container(
                    child: Card(
                      margin: EdgeInsets.only(bottom: 20),
                      elevation: 50,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(1.0),
                      ),
                      child: Column(
                        children: <Widget>[
                          Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: <Widget>[
                              Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: GestureDetector(
                                  onTap: () {
                                    print(this.records);
                                  },
                                  child: Image.asset(
                                    "assets/icons/avatar.png",
                                    height: 45,
                                  ),
                                ),
                              ),
                              Padding(
                                padding: const EdgeInsets.only(left: 5),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    Text(
                                      (this
                                          .records[index]['fields']
                                              ['Publisher Name']
                                          .toString()),
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold),
                                    ),
                                    Text(
                                      (this
                                          .records[index]['fields']['Date']
                                          .toString()),
                                      style: TextStyle(
                                        fontSize: 12,
                                      ),
                                    ),
                                  ],
                                ),
                              )
                            ],
                          ),
                          Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Container(
                              width: MediaQuery.of(context).size.width * 0.90,
                              // height: MediaQuery.of(context).size.height * 0.20,
                              decoration: BoxDecoration(
                                border: Border.all(
                                  color: Colors.purple,
                                  width: 3.0,
                                ),
                              ),
                              child: Center(
                                child: Padding(
                                  padding: const EdgeInsets.all(18.0),
                                  child: Text(
                                    (this
                                        .records[index]['fields']['Shayari']
                                        .toString()),
                                    style: TextStyle(
                                      color: Colors.green,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            children: <Widget>[
                              // Image.asset(
                              //   "assets/icons/dil.png",
                              //   height: 30,
                              // ),
                              GestureDetector(
                                onTap: () {
                                  ClipboardManager.copyToClipBoard(this
                                          .records[index]['fields']['Shayari']
                                          .toString())
                                      .then((result) {
                                    final snackBar = SnackBar(
                                      content: Text('Copied to Clipboard'),
                                    );
                                    Scaffold.of(context).showSnackBar(snackBar);
                                  });
                                  print(this
                                      .records[index]['fields']['Shayari']
                                      .toString());
                                },
                                child: Image.asset(
                                  "assets/icons/copy.png",
                                  height: 25,
                                ),
                              ),
                              GestureDetector(
                                onTap: () async {
                                  SocialShare.checkInstalledAppsForShare().then(
                                    (data) {
                                      print(data.toString());
                                    },
                                  );
                                },
                                child: Image.asset(
                                  "assets/icons/whatsapp.png",
                                  height: 35,
                                ),
                              ),
                              GestureDetector(
                                onTap: () async {
                                  Share.share(
                                      "Please Share https://google.com");
                                },
                                child: Image.asset(
                                  "assets/icons/share.png",
                                  height: 25,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 5,
                          ),
                        ],
                      ),
                    ),
                  );
                },
              ));
  }
}

在此列表中,我从Airtable调用数据: 我想在每5个列表视图项之后显示本机添加,但是我怎么做才能让我自己做到这一点?

0 个答案:

没有答案