AppBarの下にもあるグラデーションの背景を取得するために、Scaffoldをコンテナでラップします。基本的に全画面グラデーション背景。しかし、私の試みは何もしません。 AppBarの機能を維持しながら、画面全体にわたるグラデーションの上に配置する別の方法はありますか?
import 'package:flutter/material.Dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test',
theme: ThemeData(
primarySwatch: Colors.yellow,
),
home: MyHomePage(title: 'Test'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.1, 0.5, 0.7, 0.9],
colors: [
Colors.yellow[800],
Colors.yellow[700],
Colors.yellow[600],
Colors.yellow[400],
],
),
),
child: Scaffold(
appBar: AppBar(
title: Icon(Icons.menu),
backgroundColor: Color(0x00000000),
elevation: 0.0,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'dummy text',
),
Text(
'5',
style: Theme.of(context).textTheme.display1,
),
FloatingActionButton(
backgroundColor: Colors.white,
foregroundColor: Colors.black45,
elevation: 0.0,
onPressed: () {},
tooltip: 'Play',
child: Icon(Icons.play_arrow),
),
],
),
),
),
);
}
}
このコードを使用してbackground
colorをgradient
に設定しました
return MaterialApp(
home: Scaffold(
body: Container(
decoration: new BoxDecoration(
gradient: new LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromARGB(255, 25,178,238),
Color.fromARGB(255, 21,236,229)
],
)),
child: Align(
alignment: Alignment.center,
child: Image.asset(
"images/app_logo.png",
width: 128,
height: 128,
)),
),
),
);