I am very much new(learning) to Flutter and Dart, trying to create a simple login page like below.
class PageController extends StatefulWidget {
const PageController({super.key}); // Constructor
@override
State<StatefulWidget> createState() {
return _PageControllerState();
}
}
class _PageControllerState extends State<PageController> {
var activeScreen = 'login_screen';
void switchScreen() {
setState(() {
activeScreen = 'home_page';
});
}
@override
Widget build(BuildContext context) {
Widget screenWidget = LoginScreen(switchScreen);
return CupertinoApp(
home: Scaffold(
child: screenWidget),
);
}
}
Would like to maintain Widget(s) in another class to call them accordingly in my main class above:
class LoginScreen extends StatelessWidget {
const LoginScreen(this.login, {super.key});
final void Function() login;
@override
Widget build(BuildContext context) {
return Center(
child: Column (
children: [
const SizedBox(height: 80,),
const TextField( // Email starts
decoration: InputDecoration(
labelText: 'Email',
),
), // email ends
const TextField( // password starts
decoration: InputDecoration(
labelText: 'Password',
),
), // password ends
CupertinoButton( // Login button starts
onPressed: login,
child: const Row (
mainAxisSize: MainAxisSize.min,
children: [
Icon(CupertinoIcons.play_fill, color: Colors.white),
SizedBox(width: 8),
Text("Login", style: TextStyle(color: Colors.black))
],
)
) // Login button ends
],
),);
}
}
When I render the app I get an error message:
A RenderFlex overflowed by 199192 pixels on the
I trief adding padding the text fields:
contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0)
But it doesn’t seem to work. Could anyone let me know what is the mistake I am doing here and how can I fix it?
hii !! first you have to create a material app in your flutter application like this
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Flutter App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: {
'/': (context) => HomeScreen(),
'/second': (context) => SecondScreen(),
},
);
}
}
0