YAŞAM SÜRESİ — kendi widgetini yap

Musa BAL
1 min readSep 22, 2021

INPUT_PAGE.DART

import 'package:flutter/material.dart';

class InputPage extends StatefulWidget {
@override
State<InputPage> createState() => _InputPageState();
}

class _InputPageState extends State<InputPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"YAŞAM BEKLENTİSİ",
style: TextStyle(color: Colors.black87),
),
centerTitle: true,
),
body: Column(
children: <Widget>[
Expanded(
child: Row(
children: [
Expanded(
child: MyContainer(), // yazdığımız widgeti kullanıyoruz
),
Expanded(
child: MyContainer(),
),
],
),
),
Expanded(
child: MyContainer(),
),
Expanded(
child: MyContainer(),
),
Expanded(
child: Row(
children: [
Expanded(
child: MyContainer(),
),
Expanded(
child: MyContainer(renk: Colors.yellow, ), //widget parametreli
),
],
),
),
],
),
);
}
}




class MyContainer extends StatelessWidget { // Oluşturduğumuz Widget
final Color? renk;

MyContainer({this.renk=Colors.cyanAccent}); // constructor named parameter default color

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: renk, // dışarıdan gelen rengi alacak
),
);
}
}

MAIN.DART

//import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import './input_page.dart';

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
scaffoldBackgroundColor: Colors.lightBlue,
primaryColor: Colors.lightBlue),
home: InputPage(),
);
}
}

--

--