当前位置: 首页 > news >正文

Flutter_学习记录_基本组件的使用记录

1.TextWidge的常用属性

1.1TextAlign: 文本对齐属性

常用的样式有:

  • TextAlign.center 居中
  • TextAlign.left 左对齐
  • TextAlign.right 有对齐

使用案例:

body: Center(child: Text('开启 TextWidget 的旅程吧,珠珠, 开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠',textAlign: TextAlign.center),)

1.2 maxLines: 文本显示的最大行数

使用案例:

body: Center(child: Text('开启 TextWidget 的旅程吧,珠珠, 开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠',textAlign: TextAlign.center,maxLines: 2)

1.3 overFlow: 控制文本的溢出效果

常用的样式有:

  • TextOverflow.clip 直接截断
  • TextOverflow.ellipsis 被截断后,末尾处用… 来表示
  • TextOverflow.fade 最后一行有个阴影

使用案例:

body: Center(child: Text('开启 TextWidget 的旅程吧,珠珠, 开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠开启 TextWidget 的旅程吧,珠珠',textAlign: TextAlign.center,maxLines: 2,overflow: TextOverflow.ellipsis),)

1.4 style 样式

style 给文本添加样式,需要用到组件TextStyle, 查看TextStyle 的定义如下:

 const TextStyle({this.inherit = true,this.color,this.backgroundColor,this.fontSize,this.fontWeight,this.fontStyle,this.letterSpacing,this.wordSpacing,this.textBaseline,this.height,this.leadingDistribution,this.locale,this.foreground,this.background,this.shadows,this.fontFeatures,this.fontVariations,this.decoration,this.decorationColor,this.decorationStyle,this.decorationThickness,this.debugLabel,String? fontFamily,List<String>? fontFamilyFallback,String? package,this.overflow,}

使用案例:

body: Center(child: Text('开启 TextWidget 的旅程吧,珠珠',textAlign: TextAlign.center,style: TextStyle(fontSize: 25.0,color: Color.fromARGB(255, 255, 150, 150),decoration: TextDecoration.underline,decorationStyle: TextDecorationStyle.solid),),)

1.5 富文本的使用

富文本主要用到两个组件:

  • RichText
  • TextSpan

代码如下:

class TextDemo extends StatelessWidget {Widget build(BuildContext context) {return RichText(text: TextSpan(text: "你好",style: TextStyle(color: Colors.deepOrange,fontSize: 34.0,fontStyle: FontStyle.italic,fontWeight: FontWeight.bold),children: [TextSpan(text: ",zhuzhu",style: TextStyle(fontSize: 17.0,color: Colors.lightGreen))]));}
}

效果图:
在这里插入图片描述

2. Container 容器组件

2.1 Alignment 属性的使用

常用样式:

/// The top left corner.
static const Alignment topLeft = Alignment(-1.0, -1.0);
/// The center point along the top edge.
static const Alignment topCenter = Alignment(0.0, -1.0);
/// The top right corner.
static const Alignment topRight = Alignment(1.0, -1.0);
/// The center point along the left edge.
static const Alignment centerLeft = Alignment(-1.0, 0.0);
/// The center point, both horizontally and vertically.
static const Alignment center = Alignment(0.0, 0.0);
/// The center point along the right edge.
static const Alignment centerRight = Alignment(1.0, 0.0);
/// The bottom left corner.
static const Alignment bottomLeft = Alignment(-1.0, 1.0);
/// The center point along the bottom edge.
static const Alignment bottomCenter = Alignment(0.0, 1.0);
/// The bottom right corner.
static const Alignment bottomRight = Alignment(1.0, 1.0);

自定义的样式:

Alignment(x, y), x和y的取值都是 -1~1 之间,(0,0)表示居中;
x = -1 表示最左,0表示居中,1表示最右, 同时也可以设置 -1~1 直接任意的值
y = -1 表示顶部,0表示居中,1表示底部, 同时也可以设置 -1~1 直接任意的值

2.2 设置宽高和颜色

高: height
宽:width
背景色:color

2.3 Padding 内边距属性的使用

两种设置方式:

  • EdgeInsets.all(xx) 上下左右的内边距统一设置
  • EdgeInsets.fromLTRB(left, top, right, bottom) 上下左右单独设置

2.4 margin外边距属性的使用

两种设置方式:

  • EdgeInsets.all(xx) 上下左右的内边距统一设置
  • EdgeInsets.fromLTRB(left, top, right, bottom) 上下左右单独设置

2.5 decoration 属性制作彩色背景

需要使用组件BoxDecoration 来设置

decoration: BoxDecoration(// LinearGradient 线性渐变,如果直接用Gradient也可以gradient: const LinearGradient(colors: [Colors.lightBlue,Colors.greenAccent,Colors.purple]))

2.6 decoration 来 添加圆角、边框、阴影

import 'package:flutter/material.dart';class TextDemo extends StatelessWidget {Widget build(BuildContext context) {return Container(color: Colors.green,child: Row(mainAxisAlignment: MainAxisAlignment.center,children: [Container(child: Icon(Icons.pool, size: 32.0, color: Colors.white),// color: Color.fromRGBO(3, 53, 255, 1.0),padding: EdgeInsets.all(8.0),margin: EdgeInsets.all(16.0),width: 90.0,height: 90.0,decoration: BoxDecoration(color: Color.fromRGBO(3, 53, 255, 1.0),// 边框// border: Border(//   top: BorderSide(//     color: Colors.orange,//     width: 3.0,//     style: BorderStyle.solid//   ),//   bottom: BorderSide(//     color: Colors.yellow,//     width: 3.0,//     style: BorderStyle.solid//   ),border: Border.all(color: Colors.orange,width: 3.0,style: BorderStyle.solid),// 圆角// borderRadius: BorderRadius.circular(8.0)borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0),bottomRight: Radius.circular(30.0),),// 阴影效果boxShadow: [BoxShadow(offset: Offset(6.0, 7.0),color: Color.fromRGBO(16, 20, 188, 1.0),blurRadius: 25.0,spreadRadius: 5.0)]),)],),);}
}

效果图如下:
在这里插入图片描述

2.6 decoration 来 添加背景图

import 'package:flutter/material.dart';class TextDemo extends StatelessWidget {Widget build(BuildContext context) {return Container(decoration: BoxDecoration(image: DecorationImage(image: NetworkImage("https://i-blog.csdnimg.cn/blog_migrate/41635df939e6dd13c6d5e2af785d358b.jpeg"),// 对齐方法alignment: Alignment.topCenter,// 重复的样式// repeat: ImageRepeat.repeatYfit: BoxFit.cover,// 颜色混合colorFilter: ColorFilter.mode(// 颜色值Colors.indigoAccent.withAlpha(122),// 混合模式BlendMode.hardLight))),// color: Colors.green,child: Row(mainAxisAlignment: MainAxisAlignment.center,children: [Container(child: Icon(Icons.pool, size: 32.0, color: Colors.white),// color: Color.fromRGBO(3, 53, 255, 1.0),padding: EdgeInsets.all(8.0),margin: EdgeInsets.all(16.0),width: 90.0,height: 90.0,decoration: BoxDecoration(color: Color.fromRGBO(3, 53, 255, 1.0),// 边框// border: Border(//   top: BorderSide(//     color: Colors.orange,//     width: 3.0,//     style: BorderStyle.solid//   ),//   bottom: BorderSide(//     color: Colors.yellow,//     width: 3.0,//     style: BorderStyle.solid//   ),border: Border.all(color: Colors.orange,width: 3.0,style: BorderStyle.solid),// 圆角// borderRadius: BorderRadius.circular(8.0)borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0),bottomRight: Radius.circular(30.0),),// 阴影效果boxShadow: [BoxShadow(offset: Offset(6.0, 7.0),color: Color.fromRGBO(16, 20, 188, 1.0),blurRadius: 25.0,spreadRadius: 5.0)]),)],),);}
}

效果图如下:
在这里插入图片描述

2.7 使用案例

body: Center(child: Container(alignment: Alignment.topLeft,width: 500.0,height: 300.0,// color: Colors.lightBlue,padding: const EdgeInsets.fromLTRB(50, 20, 10, 30), // 上下左右边距都一样的margin: const EdgeInsets.all(10.0),decoration: BoxDecoration(gradient: const LinearGradient(colors: [Colors.lightBlue,Colors.greenAccent,Colors.purple])),child: Text('开启 TextWidget 的旅程吧,珠珠',textAlign: TextAlign.left,style: TextStyle(fontSize: 45.0,color: Color.fromARGB(255, 255, 150, 150),decoration: TextDecoration.underline,decorationStyle: TextDecorationStyle.solid),),),)

3. Image图片组件的使用

3.1 Image Widget的集中加入形式

  1. Image.asset: 加载资源图片,会使打包时包体积过大
  2. Image.network: 网络资源图片,经常换的或者动态图片
  3. Image.file: 本地图片,比如相机照相后的图片预览

3.2 Fit 属性的使用

Fit 属性是说图片平铺的效果设置,用BoxFit组件来设置,主要有这几种样式:

  1. BoxFit.fill: 填充整个图片视图
    在这里插入图片描述

  2. BoxFit.contain :根据图片的比例完全展示在视图上,不会被裁剪。
    在这里插入图片描述

  3. BoxFit.cover: 根据图片的比例,填充这个视图,会被裁剪。
    在这里插入图片描述

  4. BoxFit.fitWidth 根据图片的宽度自适应视图
    在这里插入图片描述

  5. BoxFit.fitHeight 根据图片的高度,自适应视图
    在这里插入图片描述

3.3 图片背景色

  1. color: 设置背景色
  2. colorBlendMode: 混合模式, 用BlendMode组件来实现

代码案例:

child: Image.network('https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2024%2F1129%2F27ab50dfj00snowf20035d200u000tug008t008r.jpg&thumbnail=660x2147483647&quality=80&type=jpg',scale: 2.0,fit: BoxFit.fitHeight,color: Colors.greenAccent,colorBlendMode: BlendMode.difference,)

3.4 repeat属性的使用

需要使用ImageRepeat组件来实现,常用的模式有:

  1. ImageRepeat.repeat
  2. ImageRepeat.repeatX
  3. ImageRepeat.repeatY

3.5 本地图片的使用

首先,在项目的根目录中,添加一个文件夹, 命名为images,然后把图片拖进去,如下图:
在这里插入图片描述

其次,项目的pubspec.yaml的文件中,配置本地图片,如下图:
在这里插入图片描述

最后,在代码中引用Image.asset('images/picture_1.png'),代码如下:

import 'package:flutter/material.dart';void main() {runApp(MaterialApp(title: "图片本地展示",home: FirstPage()));
}class FirstPage extends StatelessWidget {const FirstPage({super.key});Widget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text("图片本地加载")),body: Center(// 引用本地图片的代码child: Image.asset('images/picture_1.png'),),);}
}

4. ListView 的初级使用

4.1 竖向列表的使用

代码案例1:

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(title: 'Flutter 的demo',home: Scaffold(appBar: AppBar(title: Text('ListView Widget'),),body: ListView(children: <Widget>[ListTile(leading: Icon(Icons.accessible_forward_outlined),title: Text('标题提标题'),),ListTile(leading: Icon(Icons.accessibility_new_outlined),title: Text('标题提标题'),),ListTile(leading: Icon(Icons.access_alarm),title: Text('标题提标题'),),],),),);}
}

代码案例2:

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(title: 'Flutter 的demo',home: Scaffold(appBar: AppBar(title: Text('ListView Widget'),),body: ListView(children: <Widget>[Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg'),Image.network('https://img1.baidu.com/it/u=1368815763,3761060632&fm=253&fmt=auto&app=138&f=JPEG?w=760&h=434'),Image.network('https://i-blog.csdnimg.cn/blog_migrate/41635df939e6dd13c6d5e2af785d358b.jpeg'),Image.network('https://img2.baidu.com/it/u=2848534206,1976619941&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=896'),],),),);}
}

效果图:
在这里插入图片描述

4.2 横向列表的使用

scrollDirection这个属性来设置列表滚动的方向:

  1. Axis.horizontal 横向滚动
  2. Axis.vertical 纵向滚动

4.3 动态列表的使用

代码案例:

import 'package:flutter/material.dart';void main() {runApp(MyApp(items: List<String>.generate(100,(i) => 'Heading $i')),);
}class MyApp extends StatelessWidget {final List<String> items;const MyApp({super.key, required this.items});Widget build(BuildContext context) {final itemList = items; // 如果items为null,则使用默认值return MaterialApp(home: Scaffold(appBar: AppBar(title: Text('Example App')),body: ListView.builder(itemCount: itemList.length,itemBuilder: (context, index) {return ListTile(title: Text(itemList[index]));},),),);}
}

5. 网络布局的使用

主要用GridView组件来实现,GridView提供了几种创建方式:

  1. GridView()
  2. GridView.builder()
  3. GridView.custom()
  4. GridView.count()

常用的属性有:

crossAxisCount: 3, 每一行展示几个item
mainAxisSpacing: 2.0, 上下的间距
crossAxisSpacing: 2.0, 左右的间距
childAspectRatio: 0.75 长和宽的比,用来设置每个子视图的大小

代码使用案例:

import 'package:flutter/material.dart';void main() {runApp(FilmExample());
}class FilmExample extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(title: "电影海报实例",home: Scaffold(appBar: AppBar(title: Text("电影海报实例"),),body: GridViewDelegateTest(),));}
}// GridViewDelegate 的使用案例
class GridViewDelegateTest extends StatelessWidget {Widget build(BuildContext context) {return GridView(gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3,  // 每一行展示几个itemmainAxisSpacing: 2.0,  // 上下的间距crossAxisSpacing: 2.0, // 左右的间距childAspectRatio: 0.75 // 长宽比),children: [Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img1.baidu.com/it/u=1368815763,3761060632&fm=253&fmt=auto&app=138&f=JPEG?w=760&h=434', fit: BoxFit.cover),Image.network('https://i-blog.csdnimg.cn/blog_migrate/41635df939e6dd13c6d5e2af785d358b.jpeg', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img1.baidu.com/it/u=1368815763,3761060632&fm=253&fmt=auto&app=138&f=JPEG?w=760&h=434', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img2.baidu.com/it/u=2848534206,1976619941&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=896', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img1.baidu.com/it/u=1368815763,3761060632&fm=253&fmt=auto&app=138&f=JPEG?w=760&h=43', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img2.baidu.com/it/u=2848534206,1976619941&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=896', fit: BoxFit.cover),Image.network('https://i-blog.csdnimg.cn/blog_migrate/41635df939e6dd13c6d5e2af785d358b.jpeg', fit: BoxFit.cover),Image.network('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg', fit: BoxFit.cover),Image.network('https://img2.baidu.com/it/u=2848534206,1976619941&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=896', fit: BoxFit.cover),Image.network('https://i-blog.csdnimg.cn/blog_migrate/41635df939e6dd13c6d5e2af785d358b.jpeg', fit: BoxFit.cover),],);}
}

效果图:
在这里插入图片描述

6. 水平方向的布局案例

水平方向布局的设置,用Row的组件来设置,其中有个小知识点:Expanded组件,是填充组件:

如果设置了3个Expanded,表示将三个视图将屏幕的宽度3等份平铺。
如果三个视图中,中间的视图用Expanded包裹着,那第一个和第三个视图按照自身的大小展示,第二个视图填充剩余的宽度。

代码案例:

import 'package:flutter/material.dart';void main() {runApp(MyExampleApp());
}class MyExampleApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(title: "布局RowWidge",home: Scaffold(appBar: AppBar(title: Text("布局RowWidge案例"),),body: Row(children: [Expanded(child: ElevatedButton(onPressed: (){},style: ElevatedButton.styleFrom(foregroundColor: Colors.white,backgroundColor: Colors.redAccent, // foreground (text) color),child: Text("红色按钮"))),Expanded(child: ElevatedButton(onPressed: (){},style: ElevatedButton.styleFrom(foregroundColor: Colors.white,backgroundColor: Colors.orangeAccent, // foreground (text) color),child: Text("橙色按钮"))),Expanded(child: ElevatedButton(onPressed: (){},style: ElevatedButton.styleFrom(foregroundColor: Colors.white,backgroundColor: Colors.blueAccent, // foreground (text) color),child: Text("蓝色按钮"))),],),),);}
}

7. 垂直方向的布局案例

Column组件来实现垂直方向的布局,代码案例:

import 'package:flutter/material.dart';void main() {runApp(MyExampleApp());
}// ---布局ColumnWidge的案例---
class MyExampleApp extends StatelessWidget {Widget build(BuildContext context) {return MaterialApp(title: "垂直方向布局案例",home: Scaffold(appBar: AppBar(title: Text("垂直方向布局案例"),),body: Column(mainAxisAlignment: MainAxisAlignment.center,  // 主轴对齐方式:垂直的crossAxisAlignment: CrossAxisAlignment.center,  // 副轴对齐方式:左右的children: [Text('111111'),Expanded(child: Text('222222')),Text('333333333333')],),),);}
}

7.1 Row和Column中mainAxisAlignment

Row和Column中有个属性mainAxisAlignment设置主轴的布局方式,主要有这六种值:

  • MainAxisAlignment.start
  • MainAxisAlignment.center
  • MainAxisAlignment.end
  • MainAxisAlignment.spaceBetween
  • MainAxisAlignment.spaceAround
  • MainAxisAlignment.spaceEvenly

以column为例,对应的效果图如下:
在这里插入图片描述

7.2 Row和Column中crossAxisAlignment

Row和Column中有个属性crossAxisAlignment设置交叉轴的布局方式,交叉轴指的是跟主轴方向垂直的轴, 主要有这四种值:

CrossAxisAlignment.start
CrossAxisAlignment.center
CrossAxisAlignment.end
CrossAxisAlignment.stretch
在这里插入图片描述

8. 层叠布局Stack案例

8.1 只有两个视图的stack的使用方法

Stack组件来实现,最少需要两个子视图,其中有个属性alignment是子控件内部按照什么对齐方式对齐:

最小是0,最大是1, 是相对于stack内部空间中,最大视图的位置来说的

代码案例:

import 'package:flutter/material.dart';void main() {runApp(MyExampleApp());
}class MyExampleApp extends StatelessWidget {Widget build(BuildContext context) {var stack = Stack(// 内部控件的对齐方式,最小是0,最大是1, 是相对于stack内部空间中,最大视图的位置来说的alignment: FractionalOffset(0.5, 0.8),  children: [CircleAvatar(backgroundImage: NetworkImage('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg'),radius: 100.0,),Container(decoration: BoxDecoration(color: Colors.blueAccent),padding: EdgeInsets.all(5.0),child: Text('ZhuZhu'),)],);return MaterialApp(title: "布局案例",home: Scaffold(appBar: AppBar(title: Text("层叠布局"),),body: Center(child: stack,),),);}
}

效果图:
在这里插入图片描述

8.2 如果stack的子视图多于2个的使用方法

如果stack子视图大于2个,那么用alignment 的对齐方式来布局,就非常的不优化,此时,可以选择Positioned组件来设置布局,代码如下:

import 'package:flutter/material.dart';void main() {runApp(MyExampleApp());
}class MyExampleApp extends StatelessWidget {Widget build(BuildContext context) {var stack = Stack(// 内部控件的对齐方式,最小是0,最大是1, 是相对于stack内部空间中,最大视图的位置来说的alignment: FractionalOffset(0.5, 0.8),  children: [CircleAvatar(backgroundImage: NetworkImage('https://pic.rmb.bdstatic.com/bjh/news/0fc6b71c59a69f39cf2e1244d10eaedc.jpeg'),radius: 100.0,),Positioned(top: 10.0,left: 10.0,child: Container(decoration: BoxDecoration(color: Colors.blueAccent),padding: EdgeInsets.all(5.0),child: Text("zhuzhu"),)),Positioned(bottom: 10.0,right: 10.0,child: Container(decoration: BoxDecoration(color: Colors.deepOrange),padding: EdgeInsets.all(5.0),child: Text("技术猪"),)),],);return MaterialApp(title: "布局案例",home: Scaffold(appBar: AppBar(title: Text("层叠布局"),),body: Center(child: stack,),),);}
}

效果图如下:
在这里插入图片描述

8.3. Positioned 组件

Positioned组件用于在Stack中定位子组件的位置。Positioned组件必须作为Stack的直接子组件使用。

Positioned 的默认构造函数如下:

const Positioned({Key? key,this.left, this.top,this.right,this.bottom,this.width,this.height,required Widget child,
})

lefttoprightbottom分别代表离Stackd的 左、上、右、底四边的距离。
widthheight用于指定需要定位元素的宽度和高度
注意,Positionedwidth、height 和其他地方的意义稍微有点区别,此处用于配合left、top 、right、 bottom来定位组件。
举个例子,在·水平方向·时,你只能指定eft、right、width三个属性中的`两个,
如指定left和width后,right会自动算出(left+width),如果同时指定三个属性则会报错,垂直方向同理。

参考文档:https://www.cnblogs.com/linuxAndMcu/p/18458616#_label1

9. 卡片布局Card案例

Card组件来实现,代码如下:

import 'package:flutter/material.dart';void main() {runApp(MyExampleApp());
}class MyExampleApp extends StatelessWidget {Widget build(BuildContext context) {var card = Card(child: Column(children: [ListTile(title: Text("福建省厦门市湖里区", style: TextStyle(fontWeight: FontWeight.w700)),subtitle: Text("zhuzhu:15100001234"),leading: Icon(Icons.account_box, color: Colors.blueAccent),),Divider(),ListTile(title: Text("北京市海淀区中关村", style: TextStyle(fontWeight: FontWeight.w700)),subtitle: Text("guoguo:15100001234"),leading: Icon(Icons.account_box, color: Colors.blueAccent),),Divider(),ListTile(title: Text("上海市浦江区", style: TextStyle(fontWeight: FontWeight.w700)),subtitle: Text("xuexue:15100001234"),leading: Icon(Icons.account_box, color: Colors.blueAccent),),],),);return MaterialApp(title: "布局案例",home: Scaffold(appBar: AppBar(title: Text("层叠布局"),),body: Center(child: card,),),);}

效果图:
在这里插入图片描述

10. PageView的使用

PageView 的组件相当于iOS的UIScrollView视图,常用的应该是两种方法:

  1. PageView()
  2. PageView.builder()

10.1 PageView() 方法的使用 案例

// 用PageView() 的方法创建视图
class PageViewDemo1 extends StatelessWidget {const PageViewDemo1({super.key});Widget build(BuildContext context) {return PageView(// 设置滚动的方向scrollDirection: Axis.horizontal,// 设置选中页面的回调onPageChanged: (currentPage) {print("选中了第$currentPage页");},controller: PageController(// 默认展示第几个页面initialPage: 1,// 是否记住上次滚动的页面位置keepPage: false,// 设置页面在屏幕展示的大小,默认为1,全屏展示viewportFraction: 0.85),children: [Container(color: Colors.brown,alignment: Alignment(0, 0),child: Text("ONe",style: TextStyle(fontSize: 32.0, color: Colors.white),),),Container(color: Colors.purple,alignment: Alignment(0, 0),child: Text("TWO",style: TextStyle(fontSize: 32.0, color: Colors.white),),),Container(color: Colors.orange,alignment: Alignment(0, 0),child: Text("THREE",style: TextStyle(fontSize: 32.0, color: Colors.white),),),],);}
}

10.2 PageView.builder 方法的使用案例

// 用PageView.builder的方法创建视图
class PageViewBuilerDemo  extends StatelessWidget {const PageViewBuilerDemo({super.key});Widget build(BuildContext context) {return PageView.builder(itemCount: posts.length,itemBuilder: _pageItemBuilder);}Widget _pageItemBuilder(BuildContext context, int index) {return Stack(children: [SizedBox.expand(child: Image.network(posts[index].imageUrl, fit: BoxFit.cover),),Positioned(right: 16.0,bottom: 16.0,child: Column(children: [Text(posts[index].title, style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),),Text(posts[index].author, style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.normal))],))],);}
}

效果图如下:
请添加图片描述

相关文章:

Flutter_学习记录_基本组件的使用记录

1.TextWidge的常用属性 1.1TextAlign: 文本对齐属性 常用的样式有&#xff1a; TextAlign.center 居中TextAlign.left 左对齐TextAlign.right 有对齐 使用案例&#xff1a; body: Center(child: Text(开启 TextWidget 的旅程吧&#xff0c;珠珠, 开启 TextWidget 的旅程吧&a…...

C语言实现统计数组正负元素相关数据

在编程的世界里&#xff0c;对数组中元素的统计分析是常见的需求。今天&#xff0c;我们就来探讨一段用C语言实现的代码&#xff0c;它能统计数组中负数的个数以及正数的平均值。 代码功能概述 这段C语言代码的主要功能是&#xff1a;首先从用户处获取一个整数 n &#xff0c;用…...

AJAX RSS Reader:技术解析与应用场景

AJAX RSS Reader:技术解析与应用场景 引言 随着互联网的快速发展,信息量呈爆炸式增长。为了方便用户快速获取感兴趣的信息,RSS(Really Simple Syndication)技术应运而生。AJAX RSS Reader作为一种基于AJAX技术的信息读取工具,在用户体验和信息获取方面具有显著优势。本…...

使用openwrt搭建ipsec隧道

背景&#xff1a;最近同事遇到了个ipsec问题&#xff0c;做的ipsec特性&#xff0c;ftp下载ipv6性能只有100kb, 正面定位该问题也蛮久了&#xff0c;项目没有用openwrt, 不过用了开源组件strongswan, 加密算法这些也是内核自带的&#xff0c;想着开源的不太可能有问题&#xff…...

将5分钟安装Thingsboard 脚本升级到 3.9

稍微花了一点时间&#xff0c;将5分钟安装Thingsboard 脚本升级到最新版本 3.9。 [rootlab5 work]# cat one-thingsboard.shell echo "test on RHEL 8.10 " source /work/java/install-java.shell source /work/thingsboard/thingsboard-rpm.shell source /work/po…...

Linux---架构概览

一、Linux 架构分层的深度解析 1. 用户空间&#xff08;User Space&#xff09; 用户空间是应用程序运行的环境&#xff0c;与内核空间隔离&#xff0c;确保系统稳定性。 应用程序层&#xff1a; 用户程序&#xff1a;如 edge、vim&#xff0c;通过调用标准库&#xff08;如 …...

dnf妖气追踪找门方案

第一种 跟之前一样还是确定boss的 位置,但是妖气追踪有几个boss位置重复的思路就是分两大类第一类就是boss位置不一样的,第二类在boss位置一样的大类 下面再分一一个小类, 这个小类就是boss位置重复的下面判断 第一个门蓝色人的位置 来确定后面门的路线还有一种情况就是在选择…...

【C语言练习题】整数和实数在计算机中的二进制表示

1. 请写出下列十进制整数在计算机中的二进制存储形式&#xff08;假设为16位整数&#xff09;&#xff1a; 32767&#xff1a; -1&#xff1a; 32768&#xff1a; -2&#xff1a; 答案&#xff1a; 0111111111111111 1111111111111111 1000000000000000 1111111111111110 解…...

OSCP:Windows 服务提权详解

在Windows操作系统中&#xff0c;服务是一种特殊的后台进程&#xff0c;它们通常以较高的权限&#xff08;如 SYSTEM 或 Administrator&#xff09;运行。攻击者可以通过控制服务的创建、配置或运行过程实现权限提升&#xff08;提权&#xff09;。本文将详细分析Windows服务提…...

寻找两个正序数组的中位数:分治法与二分查找的结合

寻找两个正序数组的中位数&#xff1a;分治法与二分查找的结合 在算法领域&#xff0c;“寻找两个正序数组的中位数” 是一道经典的高频面试题&#xff08;LeetCode 第 4 题&#xff09;。它不仅考察基本的数组操作&#xff0c;还涉及二分查找与分治思想的结合。今天&#xff…...

Python-基于PyQt5,json和playsound的通用闹钟

前言&#xff1a;刚刚结束2024年秋季学期的学习&#xff0c;接下来我们继续来学习PyQt5。由于之前我们已经学习了PyQt5以及PyUIC,Pyrcc和QtDesigner的安装&#xff0c;配置。所以接下来我们一起深入PyQt5&#xff0c;学习如何利用PyQt5进行实际开发-基于PyQt5&#xff0c;json和…...

51单片机开发:定时器中断

目标&#xff1a;利用定时器中断&#xff0c;每隔1s开启/熄灭LED1灯。 外部中断结构图如下图所示&#xff0c;要使用定时器中断T0&#xff0c;须开启TE0、ET0。&#xff1a; 系统中断号如下图所示&#xff1a;定时器0的中断号为1。 定时器0的工作方式1原理图如下图所示&#x…...

循序渐进kubernetes-RBAC(Role-Based Access Control)

文章目录 概要Kubernetes API了解 Kubernetes 中的 RBACRoles and Role Bindings:ClusterRoles and ClusterRoleBindings检查访问权限&#xff1a;外部用户结论 概要 Kubernetes 是容器化应用的强大引擎&#xff0c;但仅仅关注部署和扩展远远不够&#xff0c;集群的安全同样至…...

在Scene里面绘制编辑工具

功能要求 策划要在scene模式下编辑棋子摆放。用handle.GUI绘制来解决了。 问题 在scene模式下编辑产生的数据&#xff0c;进入游戏模式后就全不见了。改为executeAlways也没用。我的解决办法是把编辑数据序列化保存到本地。在OnEnable的时候再读取。但是我忽然想到&#xff…...

深入探索 Vue 3 Markdown 编辑器:高级功能与实现

目录 1. 为什么选择 Markdown 编辑器&#xff1f;2. 选择合适的 Markdown 编辑器3. 安装与基本配置安装 配置 Markdown 编辑器代码说明 4. 高级功能实现4.1 实时预览与双向绑定4.2 插入图片和图像上传安装图像上传插件配置图像上传插件 4.3 数学公式支持安装 KaTeX配置 KaTeX 插…...

动手学图神经网络(3):利用图神经网络进行节点分类 从理论到实践

利用图神经网络进行节点分类:从理论到实践 前言 在之前的学习中,大家对图神经网络有了初步的了解。本次教程将深入探讨如何运用图神经网络(GNNs)来解决节点分类问题。在节点分类任务里,大家往往仅掌握少量节点的真实标签,却要推断出其余所有节点的标签,这属于归纳式学…...

具身智能研究报告

参考&#xff1a; &#xff08;1&#xff09;GTC大会&Figure&#xff1a;“具身智能”奇点已至 &#xff08;2&#xff09;2024中国具身智能创投报告 &#xff08;3&#xff09;2024年具身智能产业发展研究报告 &#xff08;4&#xff09;具身智能行业深度&#xff1a;发展…...

LabVIEW春节快乐

尊敬的LabVIEW开发者与用户朋友们&#xff1a; 灵蛇舞动辞旧岁&#xff0c;春风送暖贺新年&#xff01;值此癸巳蛇年新春佳节来临之际&#xff0c;向每一位深耕LabVIEW开发领域的伙伴致以最诚挚的祝福&#xff1a;愿您与家人在新的一年里平安顺遂、阖家幸福&#xff0c;事业如…...

MybatisX插件快速创建项目

一、安装插件 二、创建一个数据表测试 三、IDEA连接Mysql数据库 四、选择MybatiX构造器 五、配置参数 六、项目结构...

技术周总结 01.13~01.19 周日(Spring Visual Studio git)

文章目录 一、01.14 周二1.1&#xff09;问题01&#xff1a;Spring的org.springframework.statemachine.StateMachine 是什么&#xff0c;怎么使用&#xff1f;:如何使用StateMachine&#xff1a; 1.2&#xff09;问题02&#xff1a;Spring StateMachine 提供了一系列高级特性 …...

【C++】List的模拟实现

文章目录 1.ListNode 结构体2.List成员变量与typedef3.迭代器iterator4.begin()、end()、size()、empty()、构造函数5. insert()、erase()6.push_back()、pop_back()、push_front()、pop_front()7.拷贝构造、赋值、析构8.总代码 以后有时间会更新其它成员函数 1.ListNode 结构…...

剑指 Offer II 002. 二进制加法

comments: true edit_url: https://github.com/doocs/leetcode/edit/main/lcof2/%E5%89%91%E6%8C%87%20Offer%20II%20002.%20%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8A%A0%E6%B3%95/README.md 剑指 Offer II 002. 二进制加法 题目描述 给定两个 01 字符串 a 和 b &#xff0c;请计算…...

(15)基于状态方程的单相自耦变压器建模仿真

1. 引言 2. 单相降压自耦变压器的状态方程 3. 单相降压自耦变压器的simulink仿真模型 4. 实例仿真 5. 总结 1. 引言 自耦变压器的原边和副边之间存在直接的电气连接,所以功率是通过感应和传导从原边转移到副边的,这与双绕组变压器不同,后者的原边和副边是电气隔离的。从…...

03.01、三合一

03.01、[简单] 三合一 1、题目描述 三合一。描述如何只用一个数组来实现三个栈。 你应该实现push(stackNum, value)、pop(stackNum)、isEmpty(stackNum)、peek(stackNum)方法。stackNum表示栈下标&#xff0c;value表示压入的值。 构造函数会传入一个stackSize参数&#xf…...

.git/hooks/post-merge 文件的作用

.git/hooks/post-merge 文件是 Git 版本控制系统中的一个钩子&#xff08;hook&#xff09;脚本&#xff0c;其作用是在合并&#xff08;merge&#xff09;操作完成后自动执行一些特定的操作。以下是关于 .git/hooks/post-merge 文件作用的详细解释&#xff1a; 作用 自动化任…...

SpringBoot项目创建

一、创建新的工程 二、配置pom.xml文件 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http…...

评估训练模型所需的算力

1.模型规模(核心因素) 1.1 参数量决定算力下限: 10亿参数模型:需约1-10 PetaFLOP/s-days(等效1万亿次浮点运算持续1天) 千亿参数(如GPT-3):约3,000-5,000 PetaFLOP/s-days 万亿参数模型:超过50,000 PetaFLOP/s-days 1.2 显存需求公式: 显存(GB) ≈ (参数量 20 by…...

Tez 0.10.1安装

个人博客地址&#xff1a;Tez 0.10.1安装 | 一张假钞的真实世界 具体安装步骤参照官网安装手册即可。此处只对官网手册进行补充。 从官网下载apache-tez-0.10.1-bin.tar.gz进行安装未成功&#xff0c;出现下面的异常。最终按照官网源代码编译的方式安装测试成功。 环境 Had…...

代码随想录算法训练营第三十八天-动态规划-完全背包-139.单词拆分

类似于回溯算法中的拆分回文串题目是要求拆分字符串&#xff0c;问这些字符串是否出现在字典里。但这道题可以反着来考虑&#xff0c;从字典中的单词能不能组成所给定的字符串 如果这样考虑&#xff0c; 这个字符串就背包&#xff0c;容器字典中的单词就是一个一个物品问题就转…...

selenium clear()方法清除文本框内容

在使用Selenium进行Web自动化测试时&#xff0c;清除文本框内容是一个常见的需求。这可以通过多种方式实现&#xff0c;取决于你使用的是哪种编程语言&#xff08;如Python、Java等&#xff09;以及你的具体需求。以下是一些常见的方法&#xff1a; 1. 使用clear()方法 clear…...

新增文章功能

总说 过程参考黑马程序员SpringBoot3Vue3全套视频教程&#xff0c;springbootvue企业级全栈开发从基础、实战到面试一套通关_哔哩哔哩_bilibili 之前又偷懒几天。回老家没事干&#xff0c;玩也玩不好&#xff0c;一玩老是被家里人说。写代码吧还是&#xff0c;他们都看不懂&a…...

【设计测试用例自动化测试性能测试 实战篇】

&#x1f308;个人主页&#xff1a;努力学编程’ ⛅个人推荐&#xff1a; c语言从初阶到进阶 JavaEE详解 数据结构 ⚡学好数据结构&#xff0c;刷题刻不容缓&#xff1a;点击一起刷题 &#x1f319;心灵鸡汤&#xff1a;总有人要赢&#xff0c;为什么不能是我呢 设计测试用例…...

【算法与数据结构】动态规划

目录 基本概念 最长递增子序列&#xff08;中等&#xff09; 最大子数组和&#xff08;中等&#xff09; 基本概念 重叠子问题 一个问题可以被分解为多个子问题&#xff0c;并且这些子问题在求解过程中会被多次重复计算。例如&#xff0c;在计算斐波那契数列时&#xff0c;…...

扣子平台音频功能:让声音也能“智能”起来。扣子免费系列教程(14)

在数字化时代&#xff0c;音频内容的重要性不言而喻。无论是在线课程、有声读物&#xff0c;还是各种多媒体应用&#xff0c;音频都是传递信息、增强体验的关键元素。扣子平台的音频功能&#xff0c;为开发者和内容创作者提供了一个强大而灵活的工具&#xff0c;让音频的使用和…...

【CS61A 2024秋】Python入门课,全过程记录P4(Week7 Generators开始,更新于2025/1/29)

文章目录 关于基本介绍&#x1f44b;新的问题更好的解决方案Week7Mon Generators阅读材料Lab 05: Iterators, MutabilityQ1: WWPD: List-MutationQ2: Insert Items 关于 个人博客&#xff0c;里面偶尔更新&#xff0c;最近比较忙。发一些总结的帖子和思考。 江湖有缘相见&…...

JUC--ConcurrentHashMap底层原理

ConcurrentHashMap底层原理 ConcurrentHashMapJDK1.7底层结构线程安全底层具体实现 JDK1.8底层结构线程安全底层具体实现 总结JDK 1.7 和 JDK 1.8实现有什么不同&#xff1f;ConcurrentHashMap 中的 CAS 应用 ConcurrentHashMap ConcurrentHashMap 是一种线程安全的高效Map集合…...

【Linux网络编程】网络层说明

目录 前言&#xff1a; 1&#xff0c;网络层介绍 2&#xff0c;IP协议 3&#xff0c;IP协议的格式 4&#xff0c;网段划分 5&#xff0c;特殊的IP地址 6&#xff0c;私有IP地址和公网IP地址 前言&#xff1a; 网络层对于程序员来说不太重要&#xff0c;这方面知识大致了…...

002-基于Halcon的图像几何变换

本节将简要介绍Halcon中有关图像几何变换的基本算子及其应用&#xff0c;主要涉及五种常见的二维几何变换形式&#xff1a;平移、镜像、旋转、错切和放缩。这几种变换可归结为一类更高级更抽象的空间变换类型&#xff0c;即仿射变换&#xff08;Affine transformation&#xff…...

unity学习22:Application类其他功能

目录 1 是否允许后台运行 1.1 Application.runInBackground&#xff0c;显示是否允许后台运行 1.2 设置的地方 2 打开URL 2.1 Application.OpenURL("") 打开超链接 3 退出游戏 3.1 Application.Quit() 退出游戏 4 场景相关 5 返回游戏状态 6 控制游戏的行…...

配置cursor进行Java springboot项目开发

本文用于记录如何配置cursor进行Java SpringBoot项目开发&#xff0c;因为项目团队同事基本都是在使用idea开发工具&#xff0c;所以在尝试cursor新ide的时候发现还是有一些小坑要处理一下的。 首先为了后续在多个不同的java项目之间进行切换的时候不想翻来覆去的总配置指定jdk…...

ChirpIoT技术的优势以及局限性

ChirpIoT是一种由上海磐启微电子开发的国产无线射频通讯技术&#xff0c;ChirpIoT技术基于磐启多年对雷达等线性扩频信号的深入研究&#xff0c;并在此基础上对线性扩频信号的变化进行了改进&#xff0c;实现了远距离传输的一种无线通信技术。相关产品型号有E29-400T22D、E290-…...

ODP(OBProxy)路由初探

OBProxy路由策略 Primary Zone 路由 官方声明默认情况&#xff0c;会将租户请求发送到租户的 primary zone 所在的机器上&#xff0c;通过 Primary Zone 路由可以尽量发往主副本&#xff0c;方便快速寻找 Leader 副本。另外&#xff0c;设置primary zone 也会在一定成都上减少…...

【25考研】人大计算机考研复试该怎么准备?有哪些注意事项?

人大毕竟是老牌985&#xff0c;复试难度不会太低&#xff01;建议同学认真复习&#xff01;没有机试还是轻松一些的&#xff01; 一、复试内容 由公告可见&#xff0c;复试包含笔试及面试&#xff0c;没有机试&#xff01; 二、参考书目 官方无给出参考书目&#xff0c;可参照…...

阿里云域名备案

一、下载阿里云App 手机应用商店搜索"阿里云",点击安装。 二、登录阿里云账号 三、打开"ICP备案" 点击"运维"页面的"ICP备案"。 四、点击"新增网站/App" 若无备案信息,则先新增备案信息。 五、开始备案...

实现基础的shell程序

1. 实现一个基础的 shell 程序&#xff0c;主要完成两个命令的功能 cp 和 ls 1.1.1. cp 命令主要实现&#xff1a; ⽂件复制⽬录复制 1.1.2. ls 命令主要实现&#xff1a; ls -l 命令的功能 1.1. 在框架设计上&#xff0c;采⽤模块化设计思想&#xff0c;并具备⼀定的可扩…...

yolov5错误更改与相关参数详解(train.py)

1.错误更改 main中相关参数 if __name__ __main__:parser argparse.ArgumentParser()parser.add_argument(--weights, typestr, default, helpinitial weights path)parser.add_argument(--cfg, typestr, defaultmodels/yolov5s.yaml, helpmodel.yaml path)parser.add_arg…...

(详细)Springboot 整合动态多数据源 这里有mysql(分为master 和 slave) 和oracle,根据不同路径适配不同数据源

文章目录 Springboot 整合多动态数据源 这里有mysql&#xff08;分为master 和 slave&#xff09; 和oracle1. 引入相关的依赖2. 创建相关配置文件3. 在相关目录下进行编码&#xff0c;不同路径会使用不同数据源 Springboot 整合多动态数据源 这里有mysql&#xff08;分为maste…...

20.Word:小谢-病毒知识的科普文章❗【38】

目录 题目​ NO1.2.3文档格式 NO4.5 NO6.7目录/图表目录/书目 NO8.9.10 NO11索引 NO12.13.14 每一步操作完&#xff0c;确定之后记得保存最后所有操作完记得再次删除空行 题目 NO1.2.3文档格式 样式的应用 选中应用段落段落→开始→选择→→检查→应用一个一个应用ctr…...

arkui-x跨平台与android java联合开发

华为鸿蒙系统采用的是arkts&#xff0c;支持跨平台crossplatform 即前端为arkts&#xff0c;arkui-x框架&#xff0c;后端为其他的语言框架。 本篇示例后端采用的是java&#xff0c;android studio工程。 主要方式是前端鸿蒙完成界面元素、布局等效果&#xff0c;后面androi…...

G. Rudolf and CodeVid-23

题目链接&#xff1a;Problem - G - Codeforces 题目大意&#xff1a; 一种病有 n≤10 种症状。 一种病情可以用一个长度为 n 的01 串表示&#xff0c;其中第 i 个字符表示是否出现该种症状。 现有 m(∑m≤103) 种药&#xff0c;每种药用两个无交集的 01 串表示。第一个 01…...