errors in my main.dart on line 21 the return statement and error in my auth,dart on line 18 the map

Issue

This Content is from Stack Overflow. Question asked by Robert Balinda

main.dart

import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:lewandowski/models/bro.dart';
import 'package:lewandowski/services/auth.dart';
import 'package:lewandowski/wrapper.dart';
import 'package:lewandowski/models/bro.dart';
import 'package:lewandowski/services/auth.dart';
import 'package:provider/provider.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return StreamProvider<Bro>.value(
        value: AuthService().user,
      child: MaterialApp(
 home: Wrapper(),
      ),
    );

  }
}

auth.dart

[import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:lewandowski/models/bro.dart';

class AuthService{
  // method to sign in anon
  final FirebaseAuth _auth = FirebaseAuth.instance;

  Bro? get bro => null;
  // create an object based on firebaseuser
  Bro? _userfromFirebaseUser(Bro user){
    return User != null ? Bro(uid:user.uid) : null;
  }
// change user stream

    Stream<Bro> get user {
    return _auth.authStateChanges
        .map(_userfromFirebaseUser(bro!));
  }
  Future signAnon() async {
    try {
      UserCredential result = await _auth.signInAnonymously();
      User? user = result.user;
      return user;
    }
    catch (e) {
      print(e.toString());

      return null;
    }
  }


  // method to sign in with email and password

  // method to sign up with email and password

  //method to sign out


}][1]

Running Gradle task ‘assembleDebug’…
lib/main.dart:21:37: Error: Required named parameter ‘initialData’ must be provided.
return StreamProvider.value(
^
../flutter/.pub-cache/hosted/pub.dartlang.org/provider-6.0.3/lib/src/async_provider.dart:102:3: Context: Found this candidate, but the arguments don’t match.
StreamProvider.value({
^^^^^^^^^^^^^^^^^^^^
lib/services/auth.dart:18:10: Error: The method ‘map’ isn’t defined for the class ‘Stream<User?> Function()’.

  • ‘Stream’ is from ‘dart:async’.
  • ‘User’ is from ‘package:firebase_auth/firebase_auth.dart’ (‘../flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.9.0/lib/firebase_auth.dart’).
    Try correcting the name to the name of an existing method, or defining a method named ‘map’.
    .map(_userfromFirebaseUser(bro!));
    ^^^

FAILURE: Build failed with an exception.

  • Where:
    Script ‘E:Developmentflutterpackagesflutter_toolsgradleflutter.gradle’ line: 1156

  • What went wrong:
    Execution failed for task ‘:app:compileFlutterBuildDebug’.

Process ‘command ‘E:Developmentflutterbinflutter.bat” finished with non-zero exit value 1

  • Try:

Run with –stacktrace option to get the stack trace.
Run with –info or –debug option to get more log output.
Run with –scan to get full insights.

BUILD FAILED in 3m 51s
Exception: Gradle task assembleDebug failed with exit code 1



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?