Flutter 如何将小部件/文本添加到容器的边框?
我希望向容器的边框添加一些文本,以便作为容器内容的帮助文本。我是个新手,有人能帮我吗。没有任何直接的方法。您必须使用和Widget来实现 这里我演示了如何使用Flutter 如何将小部件/文本添加到容器的边框?,flutter,Flutter,我希望向容器的边框添加一些文本,以便作为容器内容的帮助文本。我是个新手,有人能帮我吗。没有任何直接的方法。您必须使用和Widget来实现 这里我演示了如何使用 import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppStat
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Demo'),
),
body: Stack(
children: <Widget>[
SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: <Widget>[
Column(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(border: Border.all(style: BorderStyle.solid,color: Colors.red,width: 5.0)),
child: Center(
child: Text("hello world"),
),
),
),
],
),
],
),
),
),
Positioned(
top: 0.0,
left: 20.0,
child: Container(
child: new Text("comment",style: TextStyle(fontSize: 20.0),),
color: Colors.white,
)
),
],
),
));
}
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“演示”,
家:脚手架(
appBar:appBar(
标题:文本(“演示”),
),
主体:堆栈(
儿童:[
安全区(
孩子:填充(
填充:常数边集全部(8.0),
子:堆栈(
儿童:[
纵队(
儿童:[
扩大(
子:容器(
装饰:框装饰(边框:border.all(样式:BorderStyle.solid,颜色:Colors.red,宽度:5.0)),
儿童:中心(
孩子:文本(“你好世界”),
),
),
),
],
),
],
),
),
),
定位(
排名:0.0,
左:20.0,
子:容器(
子项:新文本(“注释”,样式:TextStyle(fontSize:20.0),),
颜色:颜色,白色,
)
),
],
),
));
}
}
没有任何直接的方法可以做到这一点。您必须使用和Widget来实现
这里我演示了如何使用
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Demo'),
),
body: Stack(
children: <Widget>[
SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: <Widget>[
Column(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(border: Border.all(style: BorderStyle.solid,color: Colors.red,width: 5.0)),
child: Center(
child: Text("hello world"),
),
),
),
],
),
],
),
),
),
Positioned(
top: 0.0,
left: 20.0,
child: Container(
child: new Text("comment",style: TextStyle(fontSize: 20.0),),
color: Colors.white,
)
),
],
),
));
}
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“演示”,
家:脚手架(
appBar:appBar(
标题:文本(“演示”),
),
主体:堆栈(
儿童:[
安全区(
孩子:填充(
填充:常数边集全部(8.0),
子:堆栈(
儿童:[
纵队(
儿童:[
扩大(
子:容器(
装饰:框装饰(边框:border.all(样式:BorderStyle.solid,颜色:Colors.red,宽度:5.0)),
儿童:中心(
孩子:文本(“你好世界”),
),
),
),
],
),
],
),
),
),
定位(
排名:0.0,
左:20.0,
子:容器(
子项:新文本(“注释”,样式:TextStyle(fontSize:20.0),),
颜色:颜色,白色,
)
),
],
),
));
}
}
添加您期望的图像外观。我无法理解“文本到边框”。制作一个自定义的ShapeOrder
类,并在paint()中进行自定义文本绘制添加您期望的图像外观。我无法理解“文本到边框”。制作一个自定义的shapeOrder
类,并在paint()方法中绘制自定义文本