Skip to content

Instantly share code, notes, and snippets.

@felipecastrosales
Created March 7, 2024 16:41
Show Gist options
  • Save felipecastrosales/c275011e2f3d9563d224ad9396a87995 to your computer and use it in GitHub Desktop.
Save felipecastrosales/c275011e2f3d9563d224ad9396a87995 to your computer and use it in GitHub Desktop.
gist_example.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Dynamic Index Example'),
),
body: DynamicIndexListView(),
),
);
}
}
class DynamicIndexListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: 16,
itemBuilder: (context, index) {
int dynamicIndex = index;
if (index == 0) {
dynamicIndex--;
return Text('Shuffle Button', style: TextStyle(fontSize: 24));
}
if (index == 4 || index == 10) {
dynamicIndex--;
return Text('Ad Banner', style: TextStyle(fontSize: 24));
}
return ListTile(
title: Text('Item $dynamicIndex'),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment