androidflutterruntime-error

NoSuchMethodError: 'text' in flutter app development


import 'package:dma_inc/widgets_common/bg_widget.dart';
import 'package:dma_inc/widgets_common/applogo_widget.dart';
import 'package:dma_inc/consts/consts.dart';
import 'package:dma_inc/widgets_common/custom_textfield.dart';
import 'package:dma_inc/widgets_common/our_button.dart';

class Loginscreen extends StatelessWidget {
  const Loginscreen({super.key});

  @override
  Widget build(BuildContext context) {
    return bgWidget(Scaffold(
      body: Center(
        child: Column(
          children: [
            (context.screenHeight * 0.1).heightBox,
            applogoWidget(),
            "Log in to $appName".text.fontFamily(bold).white.size(18).make(),
            20.heightBox,
            Column(
              children: [
                customTextfield(hint: emailHint, title: email),
                customTextfield(hint: passwordHint, title: password),
                Align(
                    alignment: Alignment.centerRight,
                    child: (TextButton(
                        onPressed: () {}, child: forgetPass.text.make()))),
                5.heightBox,
                // ourButton().box.width(context.screenWidth - 50).make(),
                ourButton(() {}, dmaRed, dmaWhite, 'login')
                    .box
                    .width(context.screenWidth - 50)
                    .make(),
              ],
            )
                .box
                .white
                .rounded
                .padding(const EdgeInsets.all(16))
                .width(context.screenWidth - 70)
                .make()
          ],
        ),
      ),
    ));
  }
}

this is where the button is used

import 'package:dma_inc/consts/consts.dart';

Widget ourButton(onPress, color, textcolor, title) {
  return ElevatedButton(
      style: ElevatedButton.styleFrom(
        backgroundColor: color,
        padding: const EdgeInsets.all(12),
      ),
      onPressed: () {
        onPress;
      },
      child: title.text.color(textcolor).fontFamily(bold).make());
}

this is where its defined

exception: Exception was thrown: NoSuchMethodError: 'text'

https://drive.google.com/file/d/1SBOOKEWNfdVIWPL_la76MsWryUFyVL2p/view?usp=sharing The whole project if you need to see that. Kindly help me fix this exception, its been 2 days and I'm still stuck.

I tried making the login just as a straight up string ('login'). I tried to remove onPassed all together.


Solution

  • Try like this.May be this will help .

    Widget ourButton(Function onPress,Color color,Color textcolor, String title) {
          return ElevatedButton(
              style: ElevatedButton.styleFrom(
                backgroundColor: color,
                padding: const EdgeInsets.all(12),
              ),
              onPressed: onPress;
              child: Text(title,style:TextStyle(color:textColor)));
        }