有什么方法可以使包装小部件动起来?当我更新新段落进行测试时,她的实际身高正在变化我的完整代码
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class HomePageCardOne extends StatefulWidget {
@override
_HomePageCardOneState createState() => _HomePageCardOneState();
}
class _HomePageCardOneState extends State<HomePageCardOne> {
String image="https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Khajuraho_-_Kandariya_Mahadeo_Temple.jpg/1200px-Khajuraho_-_Kandariya_Mahadeo_Temple.jpg";
String dummyText="Lorem Ipsum is simply dummy text of the printing and typesetting industry. scrambled it to make a type specimen book.";
@override
Widget build(BuildContext context) {
return AnimatedContainer(duration: Duration(seconds: 10),child: Wrap(
children: <Widget>[ Container(
color: Color.fromRGBO(251,246,236,1),
child: Column(
children: <Widget>[
RaisedButton(
child: Text("Animate please"),
onPressed: ()=> updateText()
),
Image.network(image,height: 150,fit: BoxFit.fill,width: MediaQuery.of(context).size.width,),
Align(
child: Padding(
padding: const EdgeInsets.only(top: 8,left: 8,bottom: 2),
child: Text("Temple Name",style: TextStyle(color: Colors.blue,fontSize: 22,fontWeight: FontWeight.bold),),
),
alignment: Alignment.centerLeft,
),
Padding(
padding: const EdgeInsets.only(left: 8,bottom: 4,top: 2),
child: Text(dummyText),
),
GestureDetector(
onTap: ()=>updateText(),
child: Text("press me"),
)
],
),
)],
),);
}
void updateText() {
setState(() {
dummyText+=dummyText;
});
}
}
这应该起作用。
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: Scaffold(body: HomePageCardOne()),
);
}
}
class HomePageCardOne extends StatefulWidget {
@override
_HomePageCardOneState createState() => _HomePageCardOneState();
}
class _HomePageCardOneState extends State<HomePageCardOne> {
String image =
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/89/Khajuraho_-_Kandariya_Mahadeo_Temple.jpg/1200px-Khajuraho_-_Kandariya_Mahadeo_Temple.jpg";
String dummyText =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. scrambled it to make a type specimen book.";
Widget m = Text(
'"Lorem Ipsum is simply dummy text of the printing and typesetting industry. scrambled it to make a type specimen book."',
key: UniqueKey());
@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: Duration(seconds: 10),
child: Wrap(
children: <Widget>[
Container(
color: Color.fromRGBO(251, 246, 236, 1),
child: Column(
children: <Widget>[
RaisedButton(
child: Text("Animate please"),
onPressed: () => updateText()),
Image.network(
image,
height: 150,
fit: BoxFit.fill,
width: MediaQuery.of(context).size.width,
),
Align(
child: Padding(
padding: const EdgeInsets.only(top: 8, left: 8, bottom: 2),
child: Text(
"Temple Name",
style: TextStyle(
color: Colors.blue,
fontSize: 22,
fontWeight: FontWeight.bold),
),
),
alignment: Alignment.centerLeft,
),
Padding(
padding: const EdgeInsets.only(left: 8, bottom: 4, top: 2),
child: AnimatedSwitcher(
duration: Duration(seconds: 3),
child: m,
)),
GestureDetector(
onTap: () => updateText(),
child: Text("press me"),
)
],
),
)
],
),
);
}
void updateText() {
setState(() {
dummyText += dummyText;
m = Text(dummyText, key: UniqueKey());
});
}
}