Skip to content

Instantly share code, notes, and snippets.

@Vanethos
Created April 21, 2020 12:41
Show Gist options
  • Save Vanethos/c33e66a0b4fea1fe50e1a70642f8a235 to your computer and use it in GitHub Desktop.
Save Vanethos/c33e66a0b4fea1fe50e1a70642f8a235 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _incrementCounter() {
setState(() {
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClassWidget(),
getWidget(),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget getWidget () => FunctionWidget();
}
class ClassWidget extends StatelessWidget {
@override
StatelessElement createElement() {
print("Created element for ClassWidget");
return super.createElement();
}
@override
Widget build(BuildContext context) {
print("Inside ClassWidget build method");
return Text("Class Widget");
}
}
class FunctionWidget extends StatelessWidget {
@override
StatelessElement createElement() {
print("Created element for FunctionWidget");
return super.createElement();
}
@override
Widget build(BuildContext context) {
print("Inside FunctionWidget build method");
return Text("Function Widget");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment