Created
November 25, 2021 14:12
-
-
Save huhuang03/badb7acfa1cc13ff9e94da656c60791a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:reorderable_grid_view/reorderable_grid_view.dart'; | |
class TestIssue24 extends StatefulWidget { | |
TestIssue24({Key? key}); | |
@override | |
_TestIssue24State createState() => _TestIssue24State(); | |
} | |
class HomePageTile { | |
int id = 10; | |
Color backgroundColor = Colors.lightGreen; | |
String name = "name"; | |
IconData tileIcon = Icons.eleven_mp_outlined; | |
} | |
class _TestIssue24State extends State<TestIssue24> { | |
List<HomePageTile> features = []; | |
_TestIssue24State() { | |
for (var i = 0; i < 50; i++) { | |
var tile = new HomePageTile(); | |
tile.id = i; | |
tile.name = 'Item$i'; | |
features.add(tile); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
/// | |
///Builds a single tile widget | |
Widget buildTile(HomePageTile tile) { | |
return GestureDetector( | |
key: ValueKey(tile.id), | |
onTap: () => { | |
print('onTap: ${tile.id}') | |
}, | |
// onTap: () => navigateFromTiles(tile.id, context), | |
child: Container( | |
padding: const EdgeInsets.all(8), | |
decoration: BoxDecoration( | |
borderRadius: const BorderRadius.all(Radius.circular(10)), | |
color: tile.backgroundColor, | |
shape: BoxShape.rectangle, | |
), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Flexible( | |
flex: 2, | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.start, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Icon( | |
tile.tileIcon, | |
size: 40, | |
color: Colors.grey[800], | |
), | |
], | |
), | |
), | |
Text( | |
tile.name, | |
style: Theme | |
.of(context) | |
.textTheme | |
.subtitle1! | |
.copyWith( | |
color: Colors.grey[800], fontWeight: FontWeight.bold), | |
), | |
]), | |
), | |
); | |
} | |
/// when the reorder completes remove the list entry from its old position | |
/// and insert it at its new index | |
void _onReorder(int oldIndex, int newIndex) { | |
setState(() { | |
final element = features.removeAt(oldIndex); | |
features.insert(newIndex, element); | |
}); | |
} | |
return ReorderableGridView.count( | |
padding: const EdgeInsets.all(10), | |
childAspectRatio: 1.7, | |
crossAxisSpacing: 10, | |
mainAxisSpacing: 10, | |
crossAxisCount: 2, | |
children: List.generate(features.length, | |
(index) => buildTile(features[index])), | |
onReorder: _onReorder, | |
footer: [], | |
); | |
} | |
} |
Thank you for your replay. Did you try the version 2.2.1
. still not work? you can post the log if 2.2.1
still not work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the quick response, probably something has to do with making the list global but here it happenes:
class HomePageTile {
HomePageTile({required this.name,
required this.backgroundColor,
required this.tileIcon});
String name;
Color backgroundColor;
IconData tileIcon;
}
//comes from a different place in the code but its global
List shownTileList = [
HomePageTile(
name: "ADD CUSTOMER",
backgroundColor: Colors.greenAccent,
tileIcon: Icons.person_add,
),
HomePageTile(
name: "ADD TILES",
backgroundColor: Colors.black,
tileIcon: Icons.add_circle_outline_outlined,
),
];
class TestIssue24 extends StatefulWidget {
TestIssue24({Key? key, required this.features}) : super(key: key);
final List features;
@OverRide
_TestIssue24State createState() => _TestIssue24State();
}
class _TestIssue24State extends State {
@OverRide
Widget build(BuildContext context) {
///
///Builds a single tile widget
Widget buildTile(HomePageTile tile) {
return GestureDetector(
key: ValueKey(tile.name),
onTap: () => {
print('onTap: ${tile.name}')
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: tile.backgroundColor,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
tile.tileIcon,
size: 40,
),
],
),
),
Text(
tile.name,
style: Theme
.of(context)
.textTheme
.subtitle1!
.copyWith(
color: Colors.grey[800], fontWeight: FontWeight.bold),
),
]),
),
);
}
}
}
class HomeController extends StatefulWidget {
const HomeController({Key? key, required this.features}) : super(key: key);
final List features;
@OverRide
State createState() => _HomeControllerState();
}
class _HomeControllerState extends State {
@OverRide
Widget build(BuildContext context) {
///
///Builds a single tile widget
Widget buildTile(HomePageTile tile) {
return GestureDetector(
key: ValueKey(tile.name),
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: tile.backgroundColor,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
tile.tileIcon,
size: 40,
color: Colors.grey[800],
),
Container(),
],
),
Text(
tile.name,
style: Theme.of(context).textTheme.subtitle1!.copyWith(
color: Colors.grey[800], fontWeight: FontWeight.bold),
),
]),
),
);
}
}
}
probably something has to do with making the list global but here it happenes