Simple code Ended with this error: Gradle task assembleDebug failed with exit code 1 - flutter

Just started flutter and ended up with this error. i made a signin.dart and run it through main.dart then i run the program the terminal endded up with this. here is my code:
import 'package:flutter/material.dart';
import 'package:flutters/view/signin.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override Widget build(BuildContext context) {
return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: SignIn(), );
} }

your problem is due to having main function in your widget.
in each application, you only have to have one single main function. after that in each widget you can have stateless or stateful widgets that are children of your main widget.
for example use this instead:
import 'package:flutter/material.dart';
import 'package:flutters/view/signin.dart';
class SimpleWidget extends StatelessWidget {
// This widget is the root of your application.
#override Widget build(BuildContext context) {
return Center(child:Text("Just A test"));
}
then you can use SimpleWidget in you main.dart

Related

Why MyApp and MaterialApp are underlined? The code is from initial flutter demo project

Started my new project - got always MaterialApp underlined. Requires bottomNavigationBar. I tried it differently: started a demo project in flutter - MyApp and MaterialApp are underlined as well. So i cannot run the project.
Here is the initial code of demo project:
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),);
}
}```
Please, tell me, what it wants? It is a code , made by flutter, i mean...
MyApp MyApp({Key? key})
package:project/main.dart
**2 positional argument(s) expected, but 1 found.
Try adding the missing arguments.**
Thank you
have you imported material app? your code should look like:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: MyTheme.appTheme,
debugShowCheckedModeBanner: false,
home: const HomeScreen(),
);
}
}

Getx controller not found even after Get.put() | Flutter | Getx

"YouController" not found. You need to call "Get.put(YouController())" or
"Get.lazyPut(()=>YouController())"
Getting this error even after I have Get.put() before coming to the screen.
Any Idea?
You can try this:
create a file named initial_bindings.dart in your lib folder. Then add this snippet to it.
import 'package:get/get.dart';
class InitialBinding implements Bindings {
#override
void dependencies() {
Get.lazyPut<YouController>(() => YouController(),fenix: true);
}
}
Then in your main.dart, add this line into your GetMaterialApp.
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: InitialBinding(), // add this line
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
Then whenever you want to access the controller, you can just use Get.find<YourController>() to use it.

How can I make sure that my main.dart is correct?

This is my main.dar and I got problems:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:pomodoroTimer/1.app_bar_pomodoro/profile/colors.dart';
import 'apilar_codigo/stacked_all.dart';
void main() async {
// initialize hive
await Hive.initFlutter();
// open a box
await Hive.openBox("Habit_Database");
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
textTheme: GoogleFonts.nunitoTextTheme(Theme.of(context).textTheme),
useMaterial3: true,
colorScheme:
ColorScheme.light(primary: ColorsToAPP.selectText)),
home: const StackePages(),
);
}
}
Is there a piece of code that I'm missing out? because I can't run the app
Thanks for any help you can provide
How can I run main.dart without problems?
You are missing the code that will actually run the app:
void main() async {
...
runApp(MyApp());
}

my flutter app isnt running the homepage i want it to

I don't know what's happening but the app is running on my root page and not on the login page
import 'package:flutter/material.dart';
import 'package:loyality/Application/Pages/Login/login_page.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Libra',
home: LoginPage(),
);
}
}

Error -32601 received from application: Method not found

I'm getting error in this code. Any help?
import 'package:flutter/material.dart';
import './homepage.dart';
void main() => (MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "Chat",
home: HomePage(),
);
}
}
In HomePage.dart file
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Chat"
),
),
);
}
}
In Debug Console it shows:
Restarted application in 2,271ms.
Error -32601 received from application: Method not found
Reloaded 0 of 496 libraries in 237ms
The issue is with your code. Your syntax for the main method doesn't make sense for running a flutter app. You likely intended to call runApp on the widget within main.
Changed main:
import 'package:flutter/material.dart';
import './homepage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "Chat",
home: HomePage(),
);
}
}
`