I am creating Flutter plugin that displays banner and interstitial ads in Flutter UI using Kotlin and Swift. When I add banner to the main.dart, there is no problem, but when I also try to display interstitial ad on button click, dart code in MyClass at first displays the correct parameters in the log inside switch case and after that, the same log is displayed with banner parameters (the log is showed twice instead of once).

Here is my code where using logs, I found that the parameters are changed:

class MyClass extends StatelessWidget {
  const MyClass(
      {super.key,
        required this.adType,
        required this.adUnitId,
        required this.width,
        required this.height
      });

  final String adType;
  final String adUnitId;
  final int width;
  final int height;

  @override
  Widget build(BuildContext context) {
      switch (defaultTargetPlatform) {
        case TargetPlatform.android:
          log("My params in Android: $adType, $adUnitId, $width, $height"); //this log is displayed twice when i click on my button
          return SizedBox(
            width: width.toDouble(),
            height: height.toDouble(),
            child: AndroidView(
                viewType: 'plugins.example.second_attempt',
                onPlatformViewCreated: (int id) {
                  onPlatformViewCreated(
                      id);
                }),
          );
        case TargetPlatform.iOS:
          log("My params in iOS: $adType, $adUnitId, $width, $height"); //this log is displayed twice when i click on my button
          return SizedBox(
            width: width.toDouble(),
            height: height.toDouble(),
            child: UiKitView(
                viewType: 'plugins.example.second_attempt',
                onPlatformViewCreated: (int id) {
                  onPlatformViewCreated(id);
                }),
          );
        default:
          return Text(
              '$defaultTargetPlatform is not yet supported by the web_view plugin');
    }
  }

  void onPlatformViewCreated(int id) {
    log("My params are wrong here: $adType, $adUnitId, $width, $height");
    MyOtherClass(myParams, id); //This is a class where I implement method channel
  }
}

And just in case here is how I use MyClass in main.dart:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              child: const Text('Press me!'),
              onPressed: () {
                setState(() {
                  _showTemp = true;
                });
              },
            ),
            if (_showTemp) const MyClass(
              adType: "interstitial",
              adUnitId: '/6499/example/interstitial',
              width: 0,
              height: 0,
            ),
            const MyClass(
              adType: "banner",
              adUnitId: '/6499/example/adaptive-banner',
              width: 300,
              height: 250,
            ),
          ],
        ),
      ),
    );
  }