Skip to content

Instantly share code, notes, and snippets.

@krharsh17
Last active April 16, 2020 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krharsh17/b5fa5cf2b7602dccf38483260805fb71 to your computer and use it in GitHub Desktop.
Save krharsh17/b5fa5cf2b7602dccf38483260805fb71 to your computer and use it in GitHub Desktop.
// Basics of dart
// Hello World
void main(){
print('Hello World!');
}
// Variables
void main(){
var lName= 'Smith';
String fName= 'Henry';
int num=10;
print(fName.runtimeType);
print(lName.runtimeType);
print(num.runtimeType);
}
// Functions
bool isNotZero(int number){
return number != 0;
}
bool isZero(int number) => number == 0;
void main(){
print(isNotZero(0));
print(isZero(0));
}
// Classes
class Car {
String engine = "E1001";
void disp() {
print(engine);
}
}
void main() {
Car c = new Car();
c.disp();
}
// Flutter Hello World
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: "My App",
home: Scaffold(
appBar: AppBar(title: Text("Hello World Application")),
body: Center(child: Text("Hello World!")))));
}
// States in Flutter
// Dartpad link: https://dartpad.dev/b6409e10de32b280b8938aa75364fa7b
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> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
// Fiddling more with states Dartpad: https://dartpad.dev/40308e0a5f47acba46ba62f4d8be2bf4
// Thanks for attending!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment