-
Notifications
You must be signed in to change notification settings - Fork 64
/
23. flutter_flexi_gridview.dart
67 lines (62 loc) · 2.27 KB
/
23. flutter_flexi_gridview.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
import 'package:flutter/material.dart';
import 'package:ig_posts/features/0.abhishvek_header.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:ig_posts/features/5.flutter_swiggy_button.dart';
import 'package:provider/provider.dart';
class FlexiGridNotifier extends ChangeNotifier {
double gridCount = 1;
void setGridCount({required double kCount}) {
gridCount = kCount;
notifyListeners();
}
}
class FlutterFlexibleGridView extends StatelessWidget {
const FlutterFlexibleGridView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
FlexiGridNotifier flexiGridNotifier({required bool renderUI}) =>
Provider.of<FlexiGridNotifier>(context, listen: renderUI);
double gridCount = flexiGridNotifier(renderUI: true).gridCount;
return Scaffold(
appBar: AppBar(
backgroundColor: bgColorFaint,
title: Text("Flutter Flexi GridView", style: boldText())),
backgroundColor: bgColor,
body: SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 20),
Slider(
activeColor: Colors.green,
inactiveColor: Colors.greenAccent,
min: 1,
max: 5,
value: gridCount,
onChanged: ((value) {
flexiGridNotifier(renderUI: false)
.setGridCount(kCount: value);
})),
GridView.builder(
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: gridCount.toInt()),
itemCount: 8,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: bgColorFaint,
image: const DecorationImage(
image: AssetImage("assets/sasuke.jpeg")),
borderRadius: BorderRadius.circular(25))),
);
},
),
const AbhishvekHeaderWidget()
],
),
),
);
}
}