build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Adsterra Demo'),
backgroundColor: Colors.teal,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 10),
// Banner Ad 728x90
const Text("Banner Ad 728x90", style: TextStyle(fontWeight: FontWeight.bold)),
BannerAd728x90(adKey: "4b28468912e38ca80a1e2530727b1d31"),
const SizedBox(height: 20),
// Native Banner Ad
const Text("Native Banner Ad", style: TextStyle(fontWeight: FontWeight.bold)),
NativeBannerAd(
scriptUrl: "//pl27574860.effectivegatecpm.com/462bebf5e6234b3a0f29d05820f1fd7b/invoke.js",
),
const SizedBox(height: 20),
// Popunder Ad
const Text("Popunder Ad (runs in background)", style: TextStyle(fontWeight: FontWeight.bold)),
PopunderAd(
scriptUrl: "//pl27574769.effectivegatecpm.com/58/db/5b/58db5b8d1af20fc3ba5e1d7ea073fb11.js",
),
const SizedBox(height: 20),
// SmartLink Download Button
const Text("SmartLink Download Button", style: TextStyle(fontWeight: FontWeight.bold)),
SmartLinkDownloadButton(
smartLinkUrl: "https://www.effectivegatecpm.com/x6y1acng?key=8763d9a9955b76c7e7dc63665cf67a8e",
downloadUrl: "https://example.com/file.zip",
),
const SizedBox(height: 20),
// Social Bar Ad
const Text("Social Bar Ad", style: TextStyle(fontWeight: FontWeight.bold)),
SocialBarAd(
scriptUrl: "//pl27574906.effectivegatecpm.com/73/32/6f/73326f5f21832b496012acfecd31ba79.js",
),
const SizedBox(height: 30),
// Referral Link for new publishers
ElevatedButton.icon(
onPressed: () {
html.window.open(
"https://beta.publishers.adsterra.com/referral/7NDyFZk52g",
"_blank",
);
},
icon: const Icon(Icons.link),
label: const Text("Create Adsterra Account with Referral"),
),
],
),
),
);
}