Saturday, April 24, 2021

Separating the widget to different files

 Widget separated to a different class file in separate pacakge/folder.


//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!",
                  textDirection: TextDirection.ltr,
                  style: TextStyle(color: Colors.white,fontSize: 36.0),
                ),
              ),
            )
        )

    );
  }
}

No comments:

Post a Comment