File>Project Structure>set project sdk> OK
2022年6月6日星期一
2022年6月5日星期日
git create a new branch and commit add all and push
First, you create your branch locally:
git checkout -b <branch-name> # Create a new branch and check it out
===================================
git add -A && git commit -m "Your Message"
===================================
The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can do:
git push <remote-name> <branch-name>
Where <remote-name> is typically origin, the name which git gives to the remote you cloned from. Your colleagues would then just pull that branch, and it's automatically created locally.
Note however that formally, the format is:
git push <remote-name> <local-branch-name>:<remote-branch-name>
But when you omit one, it assumes both branch names are the same. Having said this, as a word of caution, do not make the critical mistake of specifying only :<remote-branch-name> (with the colon), or the remote branch will be deleted!
So that a subsequent git pull will know what to do, you might instead want to use:
git push --set-upstream <remote-name> <local-branch-name>
As described below, the --set-upstream option sets up an upstream branch:
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands.
How to make a phone call
Call the launch method from url_launcher package:
launch("tel://214324234");
Emaillaunch("mailto:dfh@abdfhdfhc.com");
Flutter - Container onPressed
new GestureDetector(
onTap: (){
print("Container clicked");
},
child: new Container(
width: 500.0,
padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0),
color: Colors.green,
child: new Column(
children: [
new Text("Ableitungen"),
]
),
)
);
2022年6月4日星期六
Super Constructor
class Foo {
Foo(int a, int b) {
//Code of constructor
}
Foo.named(int c, int d) {
//Code of named constructor
}
}
class Bar extends Foo {
Bar(int a, int b) : super(a, b);
}
class Baz extends Foo {
Baz(int c, int d) : super.named(c, d);
}2022年6月3日星期五
2 state 2 button (change value and rebuild widget)
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counterA = 0;
int _counterB = 0;
void _incrementCounterA() {
setState(() {
_counterA++;
});
}
void _incrementCounterB() {
setState(() {
_counterB++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("App title"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'A:'+'$_counterA',
style: Theme.of(context).textTheme.headline4,
),
TextButton(
onPressed: _incrementCounterA,
child: const Text('A'),
),
Text(
'B:'+'$_counterB',
style: Theme.of(context).textTheme.headline4,
),
TextButton(
onPressed: _incrementCounterB,
child: const Text('B'),
),
],
),
),
);
}
}
Simple http request to setState Text\worldtime
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String strcontent = "";
void _incrementCounter () async{
Response response = await get(Uri.parse('http://worldtimeapi.org/api/timezone/Asia/Hong_Kong') );
setState(() {
print(response.body);
strcontent = response.body;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'$strcontent',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}