ERROR in flutter: widget_test.dart cannot detect MyApp()

1,358 views
Skip to first unread message

Adesanya kolade

unread,
Feb 20, 2020, 8:47:06 AM2/20/20
to Flutter Development (flutter-dev)
main.dart

import 'package:flutter/material.dart';

class Example9 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("search App"),
        actions: <Widget>[
          IconButton(icon: Icon(Icons.search), 
          onPressed: () {
            showSearch(context: context, delegate: DataSearch());

          })
        ],
      ),
      drawer: Drawer(),
    );
  }
}

class DataSearch extends SearchDelegate<String>{
 final names = [
  "Davids",
  "Aigbogun",
  "Egunbiyi",
  "Onijesude",
  "Olurindeopelopejesu"
  "AyeniFolakemi"
  "ADEGBUYIOLUDAMOLA",
  "Oyebolu"
  "AKINSOLAABISOLA",
 ];

  final recentnames = [
  "Onijesude",
  "Olurindeopelopejesu"
  "AyeniFolakemi"
  "ADEGBUYIOLUDAMOLA",
  ];

  @override
  List<WidgetbuildActions(BuildContext context) {
    return [IconButton(icon: Icon(Icons.clear), 
    onPressed: () {
      query = "";
    })];
  }
  
  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
        icon: AnimatedIcon(
          icon: AnimatedIcons.menu_arrow,
          progress: transitionAnimation,
        ),
        onPressed: (){
          close(context, null);
        });
  }

  @override
  Widget buildResults(BuildContext context) {
    return Center(
      child: Container(
        height: 100.0,
        width: 100.0,
            child: Card(
          color: Colors.red,
            child: Center(
              child: Text(query),
            ),
          ),
      ),
    );
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    final suggestionList = query.isEmpty
    ? recentnames
    : names.where((p) => p.startsWith(query)).toList();

    return ListView.builder(
      itemBuilder: (context,index)=>ListTile(
       onTap: (){
         showResults(context);
       },
      leading: Icon(Icons.location_city),
      title: RichText(text: TextSpan(
        text: suggestionList[index].substring(0,query.length),
        style: 
             TextStyle(color: Colors.black,fontWeight: FontWeight.bold),
        children: [TextSpan(
          text: suggestionList[index].substring(query.length),
          style:  TextStyle(color: Colors.grey))
        ]),
      )
    ),
     itemCount: suggestionList.length,
    );
  }

}


widget_test.dart

// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. 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:lom_search/main.dart';

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(MyApp());

    // Verify that our counter starts at 0.
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsNothing);

    // Tap the '+' icon and trigger a frame.
    await tester.tap(find.byIcon(Icons.add));
    await tester.pump();

    // Verify that our counter has incremented.
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsOneWidget);
  });
}





Screenshot (24).png



balaji ks

unread,
Feb 23, 2020, 6:12:46 AM2/23/20
to Adesanya kolade, Flutter Development (flutter-dev)
Hi,
Which flutter channel you are using?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/80803e60-0558-4de5-8c3a-8f484a63b66b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages