Skip to content

Commit

Permalink
Add docs on using BoxConstraints
Browse files Browse the repository at this point in the history
  • Loading branch information
sokoloff06 committed Nov 25, 2024
1 parent d7abe89 commit a92864f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/google_adsense/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ To [modify your responsive ad code](https://support.google.com/adsense/answer/91
1. Make sure your modifications are not breaking AdSense policies (e.g. avoid driving [unnatural attention to ads](https://support.google.com/adsense/answer/1346295?sjid=11551379421978541034-EU#Unnatural_attention_to_ads))
2. Use Flutter instruments for [adaptive and responsive design](https://docs.flutter.dev/ui/adaptive-responsive)

For example, when not using responsive `AdFormat` it is recommended to wrap adUnit widget in the `Container` with width and/or height constraints.
Note some [policies and restrictions](https://support.google.com/adsense/answer/9185043?hl=en#:~:text=Policies%20and%20restrictions) related to ad unit sizing:

<?code-excerpt "example/lib/main.dart (constraints)"?>
```dart
Container(
constraints: const BoxConstraints(maxHeight: 100),
padding: const EdgeInsets.only(bottom: 10),
child: adSense.adUnit(AdUnitConfiguration.displayAdUnit(
adSlot: '4773943862', // TODO: Replace with your own AdSlot ID
// adFormat: AdFormat.AUTO, // Not using AdFormat to make ad unit respect height constraint
)),
),
```
## Testing and common errors

### Failed to load resource: the server responded with a status of 400
Expand Down
2 changes: 2 additions & 0 deletions packages/google_adsense/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class _MyHomePageState extends State<MyHomePage> {
const Text(
'Responsive Ad Constrained by height of 100px:',
),
// #docregion constraints
Container(
constraints: const BoxConstraints(maxHeight: 100),
padding: const EdgeInsets.only(bottom: 10),
Expand All @@ -83,6 +84,7 @@ class _MyHomePageState extends State<MyHomePage> {
// adFormat: AdFormat.AUTO, // Not using AdFormat to make ad unit respect height constraint
)),
),
// #enddocregion constraints
const Text(
'Fixed 125x125 size Ad:',
),
Expand Down

0 comments on commit a92864f

Please sign in to comment.