Saturday, April 24, 2021

calling a method from a wiidget to set data to text filed

 

//main.dart

import 'package:flutter/material.dart';
import './screens/home.dart';

void main() {
   runApp(MyApp());

}


//screens/home.dart
import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        title: "Hello Flutter App",
        home: Scaffold(
            appBar: AppBar(
                title: Text("Title in App Bar separate file")
            ),
            body: Material(
              color: Colors.deepPurple,
              child: Center(
                child: Text(
                  "Hello Flutter!\n"+sayHello(),
                  textDirection: TextDirection.ltr,
                  style: TextStyle(color: Colors.white,fontSize: 36.0),
                ),
              ),
            )
        )

    );
  }
  String sayHello(){
    String hello;
    num myNum;//num means both integers and decimals
    myNum = 3.14;
    DateTime now = new DateTime.now();
    int hour = now.hour;

    hello = "Welcome to a method.:sayHello $now";
    return hello;
  }
}

No comments:

Post a Comment