How do you fix the test widget in dart

23 Views Asked by At
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:freetown_moisture/main.dart';
import 'package:freetown_moisture/sensor_zone_widget.dart';

void main() {
  testWidgets('HomeScreen UI Test', (WidgetTester tester) async {
    await tester.pumpWidget(const FreetownSoilMoistureApp());

    // Check if the title is displayed
    expect(find.text('Freetown Soil Moisture'), findsOneWidget);

    // Check if the dropdown button is displayed
    expect(find.byType(DropdownButton), findsOneWidget);

    // Check if the weather icon is displayed
    expect(find.byIcon(Icons.wb_sunny), findsOneWidget);

    // Check if the waiting message is displayed initially
    expect(find.text('Waiting for Bluetooth connection...'), findsOneWidget);

    // Example: Testing if tapping on a button navigates to a new page
    // Uncomment this section if you implement navigation logic
    /*
    await tester.tap(find.byIcon(Icons.wb_sunny));
    await tester.pump();

    // Example: Checking if the navigation occurred
    expect(find.text('WeatherPage'), findsOneWidget);
    */
  });

  testWidgets('SensorZoneWidget UI Test', (WidgetTester tester) async {
    // Create a widget for SensorZoneWidget
    final testWidget = const MaterialApp(
      home: SensorZoneWidget(zoneName: 'Test Zone', zoneNumber: null,),
    );

    await tester.pumpWidget(testWidget);

    // Check if zone name is displayed
    expect(find.text('Zone: Test Zone'), findsOneWidget);

    // Check if LOG button is displayed
    expect(find.widgetWithText(ElevatedButton, 'LOG'), findsOneWidget);

    // Check if View button is displayed
    expect(find.widgetWithText(ElevatedButton, 'View'), findsOneWidget);
  });

  // Add more test cases for other widgets if needed
}`your text`

Im getting a (A value of type 'Null' can't be assigned to a parameter of type 'int' in a const constructor. Try using a subtype, or removing the keyword 'const'.dartconst_constructor_param_type_mismatch) error for an app im trying to build im new to this so some help would be appreciated also could someone help me with connecting bluetooth with the app this is for an engineering project. :(

0

There are 0 best solutions below