flutter

void main() {
  bool result = convertToBoolLong(1);
  print(result);
  bool another = coolerWay(0);
  print(another);
}

bool convertToBoolLong(int value) {
  if (value == 0) {
    return false;
  }
  else {
    return true;
  }
}

// arrow syntax
bool coolerWay(int value) => (value == 0) ? false : true; 
void main() {
  String mySongs = sing();
  print(mySongs);
}

String sing() {
  var songs = List<String>();
  // you can avoid specifying the type of objects 
  // stored in a list by using
  // List();
  // List<int> is the generic syntax
  // generics enforce a restriction on the type of objects
  // stored in a list.
  // songs.add (python uses append)
  var songString = "";
  songs.add("Olufunmi");
  songs.add("Love is hard");
  songs.add("4 years");
  int i = 0;
  while (i < songs.length) {
    songString += "${songs[i]} - "; 
    i++;
  }
  return songString;

}
void main() {
  String mySongs = sing();
  print(mySongs);
}

String sing() {
  var songs = List<String>();
  songs.add("Flying");
  songs.add("xoom speed");
  songs.add("Evavescience");
  songs.add("always win");
  songs.add("Ming control");
  songs.add("complete control");
  var songString = "";
  // the forEach method lets you run a function on all elements
  songs.forEach((song) => songString += song + ' - ');
  return songString;
}
void main() {
  String mySongs = sing();
  print(mySongs);
}

String sing() {
  var songs = List<String>();
  songs.add("Flying");
  songs.add("xoom speed");
  songs.add("Evavescience");
  songs.add("always win");
  songs.add("Ming control");
  songs.add("complete control");
  var songString = "";
  // map transform each element of a string and returns
  // a new list
  var capitalString = songs.map((song) => song.toUpperCase());
  return capitalString.toString();
}
void main() {
  String mySongs = sing();
  print(mySongs);
}

String sing() {
  var songs = List<String>();
  songs.add("Flying");
  songs.add("xoom speed");
  songs.add("Evavescience");
  songs.add("always win");
  songs.add("Ming control");
  songs.add("complete control");
  // where only returns elements that satisfy a 
  // test expression
  var wSongs = songs.where((song) => song.contains("o"));
  return wSongs.toString();
}
void main() {
  Person faisal = Person();
  faisal.name = "Faisal";
  faisal.surname = "Muhammad";
  print('${faisal.name}, ${faisal.surname}');
}

class Person{
  String name;
  String surname;
}
void main() {
  // getters and setters are used to protect
  // property values of instances of a class
  // getters is used to retrieve properties of a class
  // setters are used to set/update properties of a class
  Person faisal = Person();
    faisal.name = "Faisal";
    faisal.surname = "Muhammad";
    faisal.level = 5;
    print("${faisal.name} ${faisal.surname} ${faisal.level}");
  
}

class Person {
  String name, surname;
  int _level;
  
  void set level(int value) {
     if (value > 0 && value < 8) {
       _level = value;
     }
     else {
       _level = 0;
     }
    // we use void because we are returning nothing
  }
    
  int get level {
    // we use int because we are returning
    // int.
    return _level;
  }
}
void main() {
  // a constructor is a special method that is 
  // automatically called
  // when an object of a class is created
  // similar to python __init__
  Person faisal = Person("Faisal", "Muhammad", 5);
//     faisal.name = "Faisal";
//     faisal.surname = "Muhammad";
//     faisal.level = 5;
    print("${faisal.name} ${faisal.surname} ${faisal.level}");
  
}

class Person {
  String name, surname;
  int _level;
  
  Person(String name, String surname, int _level) {
    this.name = name;
    this.surname = surname;
    this._level = _level;
  }
  
  void set level(int value) {
     if (value > 0 && value < 8) {
       _level = value;
     }
     else {
       _level = 0;
     }
    // we use void because we are returning nothing
  }
    
  int get level {
    // we use int because we are returning
    // int.
    return _level;
  }
}
void main() {
  // a constructor is a special method that is 
  // automatically called
  // when an object of a class is created
  // similar to python __init__
  Person faisal = Person("Faisal", "Muhammad", 5);
  Person sakina = Person();
//     faisal.name = "Faisal";
//     faisal.surname = "Muhammad";
//     faisal.level = 5;
    print("${faisal.name} ${faisal.surname} ${faisal.level}");
  
}

class Person {
  String name, surname;
  int _level;
  // optional position parameters.
  Person([this.name, this.surname, this._level]);
 // in dart you can have only one postional parameters.
//   Person();
  
  // we can have any number of named constructors
  Person.empty();
  Person.full();
  Person.hungry();
  Person.enjoy();
  Person.live();
  
  void set level(int value) {
     if (value > 0 && value < 8) {
       _level = value;
     }
     else {
       _level = 0;
     }
    // we use void because we are returning nothing
  }
    
  int get level {
    // we use int because we are returning
    // int.
    return _level;
  }
}
import "package:flutter/material.dart";

// material.dart is a package that contains reusable code of 
// widgets of  google's material design.

// runApp() attaches/stick/show a widget on the screen
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // MyApp is stateless because we are not going to 
  // change it's state/content after creation.
  @override
  // build method returns a widget
  Widget build(BuildContext context) {
    // our widget tree consist of only center and text widgets
    return Center(
      child: Text("Hello World Travel",
      textDirection: TextDirection.ltr,),
    );
  }
}
import "package:flutter/material.dart";

// material.dart is a package that contains reusable code of 
// widgets of  google's material design.

// runApp() attaches/stick/show a widget on the screen
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // MyApp is stateless because we are not going to 
  // change it's state/content after creation.
  @override
  // build method returns a widget
  Widget build(BuildContext context) {
    // our widget tree consist of only center and text widgets
    return MaterialApp(
      title: "Hello World Travel Title",
      home: Scaffold(
        // application bar.
        appBar: AppBar(title: Text("Hello World Travel App"),
        backgroundColor: Colors.deepPurple,),
        // main content of the screen.
        body: Builder(builder: (context) => SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.all(20),
          child: Center(
          child: Column(
            children: <Widget>[
              Padding(
              padding: EdgeInsets.all(10),
              child:Text("Hello World Travel",
              style: TextStyle(
                fontSize: 26,
                fontWeight: FontWeight.bold,
                color: Colors.blue[800],
              ))
              ),
              Padding(
               padding: EdgeInsets.all(5), 
              child:Text("Discover the World",
              style: TextStyle(
                fontSize: 20,
                color: Colors.deepPurpleAccent
              ))
              ),
              Padding(
              padding: EdgeInsets.all(15),  
              child:Image.network("https://images.freeimages.com/images/large-previews/80e/plane-1449434.jpg",
              height: 350,),),
              Padding(
                padding: EdgeInsets.all(15),
              child:RaisedButton(
                child: Text("Contact us"),
                onPressed: () => contactUs(context),
              ),),
            ],
          ),
        ),
      ),
      ),
      ),),
    );
  }

  // end of MyApp class
  void contactUs(BuildContext context) {
    showDialog(
      context:context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text("Contact us"),
          content: Text("Mail us at hello@world.com"),
          actions: <Widget>[
            FlatButton(
              child: Text('Close'),
              onPressed: () => Navigator.of(context).pop(),
            )
          ],
        );
      }
    );

  }
}
Padding(
	padding: EdgeInsets.all(value)
    padding: EdgeInsets.symmetric(vertical=value)
    padding: EdgeInsets.only(right:value, left:value, top:value, down:value)	
    child: //another widget
),
Text("The text exists here.",
style: TextStyle(
	fontSize:26,
    fontWeight: FontWeight.bold,
    color: Colors.blue[800],
)),
class MyApp extends StatelessWidget {
	@overrride
    Widget build(BuildContext context) {
    	return MaterialApp(
        	title: "Text",
            home: Scaffold(
            	appbar:AppBar(title: Text("text"), 
                backgroundColor: Colors.deepPurple)
                // we wanated to pass the context to the raised button
                // onPressed hence the use of builder context
                body: Builder(builder: (context) => SingleChildScrollView(
                	child: Padding(
                    	child: RaisedButton(
                        	child: Text("contact us),
                            onPressed: () => contactUs(context),
                        )
                    ),
                ))
            ),
        );      
    }
    
    void contactUs(BuildContext context) {
    	showDialog(
        	context: context,
            builder: (BuildContext context) {
            	return AlertDialogBox(
                	title: Text("Contact us),
                    content: Text("Mail us at hello@world"),
                    actions: Widget[
                    	Flatbutton(
                        	child: Text("Close"),
                            onPressed: () => Navigator.of(context).pop(),
                        ),
                    ]
                );
            }
        );
    }
}
Column(
	children: <Widget> [
    	widget,
        widget,
        widget
    ]
),
import 'package:flutter/material.dart';

// as we are building button on the screen with similar features it is
// better to create a class with properties such as color, text, size, 
// and a callback method.
class ProductivityButton extends StatelessWidget {
  final Color color;
  final String text;
  final double size;
  final VoidCallback onPressed;

  // curly brackets indicate names parameters
  // named parameters are optional so we annotate it
  // with @required to make the parameter mandatory.
  ProductivityButton({@required this.color,@required this.text,@required this.size,
  @required this.onPressed});

  @override
  Widget build(BuildContext context) {
    return MaterialButton(
      child: Text(this.text,
      style: TextStyle(color: Colors.white)),
      onPressed: this.onPressed,
      color: this.color,
      minWidth: this.size,

    );
  }
}
Row(
                children: <Widget>[
                  Padding(padding:EdgeInsets.all(defaultPadding)),
                  Expanded(child: ProductivityButton(color: Color(0xff009688), 
                  text: "Work", onPressed: emptyMethod,)),
                  Padding(padding:EdgeInsets.all(defaultPadding)),
                  Expanded(child: ProductivityButton(color: Color(0xff607D8B), 
                  text: "Short Break", onPressed: emptyMethod,)),
                  Padding(padding:EdgeInsets.all(defaultPadding)),
                  Expanded(child:ProductivityButton(color: Color(0xff455A64),
                  text: "Long Break", onPressed: emptyMethod)),
                  Padding(padding:EdgeInsets.all(defaultPadding)),
                ],
              ),
body: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
	final double availableWidth = constraints.maxWidth;
    return Center(
    	child:...
    );
}
CircularPercentIndicator(
                // in choosing the radius of the circle we would using a relative
                // size that depends on the size of the screen. We would be using
                // the LayoutBuilder which provides parents widget constraints.
                radius: availableWidth / 2.0,
                lineWidth: 10.0,
                percent: 1,
                center: Text("30:00", style: Theme.of(context).textTheme.headline4),
                progressColor: Color(0xff009688),
              )
// Besides Statefull Widget there are other ways of changing data such as Streams.

// Asyncronous programming allows a piece of code to run seperately from the main line of
// execution. This means several tasks can run at the same time(concurrently) instead of running
//sequentially.
// A stream is a sequence of results.
Stream<T> stream() async* {
	// this stream emits events at the duration specified in
    // the first parameter.
    yield* Stream.periodic(Duration(seconds: 1), (int a) {
      // declaring a new variable
      String time;
      // keep substracting 1 from time at each period of the stream cycle
      _time = _time - Duration(seconds: 1);
      // try to determine the percentage of completed time
      _radius = _time.inSeconds / _fullTime.inSeconds;
      if(_time.inSeconds <= 0) {
        _isActive = false;
      }
      // format time to be returned
      time = returnTime(_time);
      return TimerModel(time, _radius);
    });
  }
import 'package:flutter/material.dart';

class SettingsScreen extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
  	// A PopupMenuButton displays a menu when clicked, 
    // in its itemBuilder it shows a list of PopupMenuItems
    // that's why we created a list of PopupMenuItem below.

    // initializing the pop up menu
    final List<PopupMenuItem<String>> menuItems = List<PopupMenuItem<String>>();
    // adding items to the menu
    menuItems.add(
      PopupMenuItem(
        value: "Settings",
        child: Text("Settings")
      )
    );
    
    \
    
    return Scaffold(
      appBar: AppBar(title: Text("Settings"),
      actions: <Widget> [
      PopupMenuButton(
      	itemBuilder: (BuildContext context) {
        	menuItems.toList();
        },
        onSelected: (s) {
              if (s == "Settings") {
                gotoSettings(context);
              }
            }
      ),]),
      body: Container(
        child: Text("Hello World"),
      ),
    );
  }
  
  // pushing the settings screen to the top of the stack.
	void gotoSettings(BuildContext context) {
      Navigator.push(context,
        MaterialPageRoute(builder: (context) => SettingsScreen())
      );
    }  
}
GridView.count(
        // scroll direction
        scrollDirection: Axis.vertical,
        // number of items/widgets per row
        crossAxisCount: 3,
        // size of children in the gridview
        // width of children should be 3 X height
        childAspectRatio: 3,
        // As there are no space between the children of a 
        // gridView by default. we add some spacing for the 
        // main axis.
        mainAxisSpacing: 10,
        // spacing cross-axis of the main Axis
        crossAxisSpacing: 10,
        // items in our gridView
        // 3 widgets represent one row as we have crossAxisCount: 3
        children: <Widget>[],
        padding: const EdgeInsets.all(20.0),
      ),
TextField(
            style: textStyle,
            textAlign: TextAlign.center,
            keyboardType: TextInputType.number,
            controller: txtLong,
          ),
Expanded(
                child: StreamBuilder(
                  // show something while waiting for data from the stream,
                  initialData: "00:00",
                  stream: timer.stream(),
                  builder: (BuildContext context, AsyncSnapshot snapshot) {
                    // we would be saving a timer model object to this variable hence TimerModel
                    TimerModel timer = (snapshot.data == "00:00") ? TimerModel("00:00", 1): snapshot.data;
                      return Expanded(child: CircularPercentIndicator(
                        radius: availableWidth / 2.0,
                        lineWidth: 10.0,
                        percent: timer.percent, 
                        center: Text(timer.time,
                        style: Theme.of(context).textTheme.headline4),
                        progressColor: Color(0xff009688),
                      ));
                  },
                ),
              ),

Similiar Collections