I am pretty new in Dart and I have tried the following:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter App'),
),
body: Column(children: [
Card(
child: Text('CHART!!'),
),
Card(child: Text('LIST OF TX'),)
],),
);
}
}
output is:
Why the children of the column does not be placed next to each other?
Change the Column to Row if you want them to be next to each others horizontally.
To place the children next to each other use the Row widget which is very similar to Column. Please see the code below.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter App'),
),
body: Row(children: [
Card(
child: Text('CHART!!'),
),
Card(child: Text('LIST OF TX'),)
],),
);
}
}
Related
import 'package:expense_management/widgets/user_transaction.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter App'),
),
body: Column(
children: <Widget>[
Container(
width: double.infinity,
child: const Card(
color: Colors.orange,
elevation: 5,
child: Text('chart'),
),
),
userTransaction()
],
));
}
}
error--------------------
The following Unimplemented Error was thrown building Keyed
Subtree-[GlobalKey#87727]: UnimplementedError
The relevant error-causing widget was: Scaffold
Scaffold:file:///C:/Users/abhargaw/Downloads/development/projects/expense_management/lib/main.dart:21:1
2
I have reinstalled the flutter and Android Studio to my device and after that Scaffold widget is not working. It says "This method 'Scaffold' isn't defined for the type 'MyApp' "
add wrap Scaffold with MaterialApp widget
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}
I am brand new to flutter and programming in general -so please bear with me-, so I am taking a course on udemy and I stumbled with this error (The constructor being called isn't a const constructor)
This is the code :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar:AppBar(
title: Text('My First App'),
),
body: Text('This is my default text'),
),
);
}
}
Try below code hope its help to you. remove const keyword
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My First App'),
),
body: Text('This is my default text'),
),
);
}
}
Your result screen->
I used the debugShowCheckedModeBanner: false, code to remove the debug banner and it had worked fine with all of my previous apps. But now when I used this code only the shadow under debug banner get removed.
Here's my code
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 MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
I have attached the images link of debugShowCheckedModeBanner: false, and debugShowCheckedModeBanner: true,below.
How can I remove this debug banner completely, please help!
Try below code hope its help to you.
Remove MaterialApp Widget from HomeScreen Class
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('E Com App'),
),
body: Container(
color: Colors.red,
height: 200,
width: double.infinity,
child: Text(
'Red Container',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
);
}
}
Your Result Screen->
If you want MaterialApp Widget in HomeScreen class then add below line inside MaterialApp in HomeScreen Class.
debugShowCheckedModeBanner: false,
Full Widget:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('E Com App'),
),
body: Container(
color: Colors.red,
height: 200,
width: double.infinity,
child: Text(
'Red Container',
style: TextStyle(fontSize: 30, color: Colors.white),
),
),
),
);
}
}
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
//this code add it
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: HomeScreen(),
),
),
);
}
}
I am learning flutter. i have made one app name chat x(title). the code is below
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Chat X'),
),
body: Card(child: Column(children: <Widget>[
Text('hey! this one is new');
],),),
),
);
}
}
when ever i want to debug this code i get this error
Expected to find ']'.
Remove ; from Text('hey! this one is new'); or you can place a , if you want to have more widgets inside Column
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Chat X'),
),
body: Card(child: Column(children: <Widget>[
Text('hey! this one is new'),
Text('hey! this one is second new'),
],),),
),
);
}
}
You shoud not have the ; after the Text widget. Like this:
Text('hey! this one is new')