Created
March 7, 2024 16:41
-
-
Save felipecastrosales/c275011e2f3d9563d224ad9396a87995 to your computer and use it in GitHub Desktop.
gist_example.dart
This file contains hidden or 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'; | |
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