making logic in flutter
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// Import for Android features.
void main() {
runApp(MyApp());
}
//This is main homepage or we can say main body
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Color color = Theme.of(context).primaryColor;
return MaterialApp(
title: 'Welcome to flutter',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String myText = "hello world";
void changeState() {
setState(() {
if (myText.startsWith("h")) {
myText = "Welcome to flultter";
} else {
myText = "hello world";
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(
child: Text(
'Welcome to flutter',
style: TextStyle(fontWeight: FontWeight.bold),
)),
),
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(myText),
FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
changeState();
})
],
),
),
));
}
}
Comments
Post a Comment