import 'dart:ffi';
import 'package:flutter/material.dart';
/*
void main() {
// 文本显示
// runApp(const Text("Hello world", textDirection: TextDirection.ltr));
/*
// 文本居中 + 样式
runApp(
const Center(
child: Text(
"Hello world",
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 30,
color: Colors.lightGreen,
),
),
)
);
*/
/*
runApp(
const MaterialApp(
title: "hello 世界",
home: Center(
child: Text(
"Hello world",
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 30,
color: Colors.lightGreen,
),
),
),
)
);
*/
/*
runApp(
MaterialApp(
title: "你好,世界",
home: Scaffold( //脚手架
appBar: AppBar(title: Text("data")), //标题
body: const Center(
child: Text(
"Hello world",
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 30,
color: Colors.lightGreen,
),
),
),
),
)
);
*/
// runApp(
// MaterialApp(
// home: Scaffold(
// appBar: AppBar(
// title: Text("CODERWHY"),
// ),
// body: Center(
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Checkbox(value: true, onChanged: (value) => print("Hello World")),
// Text(
// "同意协议",
// textDirection: TextDirection.ltr,
// style: TextStyle(fontSize: 25),
// )
// ],
// ),
// ),
// ),
// )
// );
runApp(
MyApp()
);
}
*/
/*
main2() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("CODERWHY"),
),
body: TextWidget(),
),
);
// TODO: implement build
throw UnimplementedError();
}
}
class ContentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Checkbox(value: true, onChanged: (value) => print("Hello World")),
Text(
"bu同意协议",
textDirection: TextDirection.ltr,
style: TextStyle(fontSize: 25),
)
],
)
);
// TODO: implement build
throw UnimplementedError();
}
}
class TextWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Checkbox(value: true, onChanged: (value) => print("Hello World")),
Text(
"bu同意协议",
textDirection: TextDirection.ltr,
style: TextStyle(
fontSize: 25,
color: Colors.deepOrange,
),
)
],
)
);
// TODO: implement build
throw UnimplementedError();
}
}
*/
import 'dart:ffi';
import 'package:flutter/material.dart';
main3() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// title: "Hello world",
home: Scaffold(
// 导航栏
appBar: AppBar(
title: Text("标题"),
),
body: HomeContent(),
)
);
// TODO: implement build
// throw UnimplementedError();
}
}
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
// return Text("Hello Flutter.");
//垂直排布
return Padding(
padding: EdgeInsets.all(20),
child: ListView(
children: <Widget>[
ProductItem("2022年最大超级月亮", "亮相夜空","https://img.zcool.cn/community/01683d5a4f502ea801206ed3627d34.jpg@1280w_1l_2o_100sh.jpg"),
ProductItem("2022年最大超级月亮", "data2","https://tse4-mm.cn.bing.net/th?id=OIF-C.ds96QeIPBIWAy5%2bjIATF5w&pid=ImgDet&rs=1"),
],
),
);
// return ListView(
// children: <Widget>[
// ProductItem("2022年最大超级月亮", "亮相夜空","https://img.zcool.cn/community/01683d5a4f502ea801206ed3627d34.jpg@1280w_1l_2o_100sh.jpg"),
// ProductItem("2022年最大超级月亮", "data2","https://tse4-mm.cn.bing.net/th?id=OIF-C.ds96QeIPBIWAy5%2bjIATF5w&pid=ImgDet&rs=1"),
//
// ],
// );
}
}
class ProductItem extends StatelessWidget {
String title;
String subtitle;
String imageUrl;
int counter = 0;
ProductItem(this.title, this.subtitle, this.imageUrl);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
border: Border.all(
width: 2
)
),
child: Column(
children: <Widget>[
Text(title, style: const TextStyle(fontSize: 24),),
Text(subtitle, style: const TextStyle(fontSize: 18),),
SizedBox(height: 10),
Image.network(imageUrl)
],
),
);
}
}
import 'dart:ffi';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
main4() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("标题"),
),
body: ContentWidget(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: (){
},
),
),
);
// TODO: implement build
throw UnimplementedError();
}
}
class ContentWidget extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return ContentWidgetState();
}
}
class ContentWidgetState extends State<ContentWidget> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: (){
print("监听到点击事件");
setState(() {
counter++;
});
},
child: const Text("计数+1")
),
ElevatedButton(
onPressed: (){
print("监听到点击事件");
setState(() {
counter--;
});
},
child: const Text("计数-1")
),
],
),
Text("当前计数: $counter",
style: TextStyle(
fontSize: 30
),),
],
),
);
}
}
//不能实现
class ContentWidget2 extends StatelessWidget {
int counter = 0;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: (){
print("监听到点击事件");
//counter++;
},
child: Text("计数+1")
),
// ElevatedButton(
// onPressed: (){
// print("object")
// },
// child: Text("计数+1")
// ),
Text("当前计数: $counter",
style: TextStyle(
fontSize: 30
),),
],
),
);
// TODO: implement build
throw UnimplementedError();
}
}