下面的代码是我的按钮部分代码。
单击此按钮时,我想在“页面选择页面(下面的代码)”上显示书签按钮的边框颜色以更改颜色。
实际上最重要的部分是使用 shared_preferences: ^2.0.7 使其存储在本地。
我已经看过并尝试了几个例子,但我在第 4 天挣扎。
bool recognizing = false;
...
actions: <Widget>[
IconButton(
onPressed: recognizing ?
Function for Remove from Favorites : function to add to favorites,
icon: recognizing
? Icon(Icons.bookmark_rounded, color: Colors.yellow[800], size: 30) //그대로일때
: Icon(Icons.bookmark_add_outlined, color: Colors.yellow[800],size: 30),
),
],
下面是按钮代码。在之前的“页面选择页面”中,调用并使用下面的代码作为child:LearnLevelButton()。
class LearnLevelButton extends StatelessWidget {
LearnLevelButton({
Key ?key,
this.text = '',
this.width = 80.0,
this.height = 80.0,
this.borderRadius = 50.0,
required this.onTap,
}) : super(key: key);
final String text;
final VoidCallback onTap;
final double width;
final double height;
final double borderRadius;
@override
Widget build(BuildContext context) {
var gradient = LinearGradient(
begin: Alignment.topCenter, // new
end: Alignment.bottomCenter, // new
colors: [
//Color(0xff9cbbf6),
//Color(0xff9cbbf6),linkwell
Color(0xff7ba6f9),
Color(0xff7ba6f9),
],
);
return InkWell(
onTap: onTap,
child: Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0,
bottom: 20.0,
left: 22.0,
right: 22.0,
),
child: Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black38,
),
boxShadow: [
BoxShadow(
blurRadius: 10.0,
offset: Offset(5.0, 5.0),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
width: width,
height: height,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(borderRadius),
border: Border.all(
width: 0.3,
color: Colors.black26,
),
boxShadow: [
BoxShadow(
blurRadius: 1.0,
offset: Offset(1.0, 1.5),
color: Color.fromRGBO(0, 0, 0, 0.3),
),
],
gradient: gradient,
),
child: Center(
child: Text(
text,
style: TextStyle(
color: Colors.white,
fontSize: 20.0, fontWeight: FontWeight.bold,
),
),
),
),
),
),
),
);
}
}