-
Notifications
You must be signed in to change notification settings - Fork 225
/
gradient_image.dart
97 lines (92 loc) · 3.14 KB
/
gradient_image.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; //for making request
import 'dart:async'; //for asynchronous features
import 'dart:convert'; //PlatForm Exception
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new MyAppScreenMode();
}
}
class MyAppScreenMode extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.yellow,
),
home: new GradientBody(),
);
}
}
class GradientBody extends StatelessWidget {
final List<String> images = [
"assets/1.jpg",
"assets/2.jpg",
"assets/3.jpg",
];
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Gradients'),
),
body: new Center(
child: new SizedBox(
// width: 200.0,
height: 300.0,
//child: const Card(child: const Text('Hello World!')),
child: new PageView.builder(
//similar to listview builder except that only 1 image is allowed at each time
scrollDirection: Axis.horizontal,
controller: new PageController(
viewportFraction: 0.8, // if 1 then only 1 image in the screen
),
itemCount: images.length,
itemBuilder: (BuildContext context, int index) {
return new Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
),
child: new Material(
type: MaterialType.card,
elevation: 8.0,
borderRadius: new BorderRadius.circular(8.0),
// color: Colors.lightGreen,
// child: new Image.asset(
// images[index]
// ),
child: new Stack( //if fit not specified then, it aligns to top left....
fit: StackFit.expand,
children: <Widget>[
new Image.asset(
images[index],
fit: BoxFit.fill,
),
new DecoratedBox(
decoration: new BoxDecoration(
//color: Colors.lightGreen
gradient: new LinearGradient(
begin: FractionalOffset.bottomRight,
end: FractionalOffset.topLeft,
colors: [
const Color(0xFF001510),
const Color(0x0000bf8f),
]
)
),
),
],
),
),
);
},
),
),
),
);
}
}