You can add Adsense ad unit In Flutter Web with the help of below widget. It's work perfectly fine.
create widget with any name you like. I'm name BannerAdUnit
only replace div tag ad unit id and script add Url as you can see in the below widget inside html body tag.
import 'dart:html' as html;
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
String viewID = "your-view-id";
class BannerAdUnit extends StatelessWidget {
const BannerAdUnit({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
ui.platformViewRegistry.registerViewFactory(
viewID,
(int id) => html.IFrameElement()
..style.width = '100%'
..style.height = '100%'
..srcdoc = '''
<!DOCTYPE html>
<html> <head> </head> <body>
<div data-frill-widget="your ad unit id will come here" style="width: 340px; height: 460px;"></div>
<script async src="url"></script> </body>
</html> '''
..style.border = 'none');
return SizedBox(
height: 460,
width: 340,
child: HtmlElementView(
viewType: viewID,
),
);
}
}
The story is not end here. When you add the above code You will see one beautiful error something like that.
The name 'platformViewRegistry' is being referenced through the prefix
'ui', but it isn't defined in any of the libraries imported using that
prefix. (Documentation)
How to fix this error? Don't worry I'll show you how to fix this error.
Create new file on the root name it analysis_options.yaml
and copy and paste the below code and the error is gone.
analyzer:
errors:
undefined_prefixed_name: ignore
Note: On the debugging mode flutter Web app not show you any ads.
if you want to see ads deploy your Flutter Web App. you will see ads like this.

If you guys don't want to write these spaghetti code try this package flutter_ad_manager_web. I created this helpful package for display Adsense ads on Flutter Web.