Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Created February 23, 2025 06:15
Show Gist options
  • Save Lxxyx/f679190b6bb8d6b7d645e73e6d20cb40 to your computer and use it in GitHub Desktop.
Save Lxxyx/f679190b6bb8d6b7d645e73e6d20cb40 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Web3 News',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorSchemeSeed: Colors.blue,
),
home: const NewsHomePage(),
);
}
}
class NewsHomePage extends StatefulWidget {
const NewsHomePage({super.key});
@override
_NewsHomePageState createState() => _NewsHomePageState();
}
class _NewsHomePageState extends State<NewsHomePage> {
int _selectedIndex = 0;
List<String> _circleNames = ['Crypto', 'DeFi', 'NFTs', 'Gaming'];
List<List<NewsItem>> _newsItems = [
[ // Crypto circle
NewsItem('Bitcoin Price Hits New High', 'https://example.com/bitcoin'),
NewsItem('Ethereum Network Congestion', 'https://example.com/ethereum'),
NewsItem('Crypto Market Capitalization', 'https://example.com/crypto-market'),
],
[ // DeFi circle
NewsItem('Uniswap Launches New Token', 'https://example.com/uniswap'),
NewsItem('Lending Markets on the Rise', 'https://example.com/lending-markets'),
NewsItem('DeFi TVL Reaches New High', 'https://example.com/defi-tvl'),
],
[ // NFTs circle
NewsItem('Rare NFT Sold for 100 ETH', 'https://example.com/rare-nft'),
NewsItem('NFT Market Grows 50%', 'https://example.com/nft-market'),
NewsItem('New NFT Platform Launches', 'https://example.com/new-nft-platform'),
],
[ // Gaming circle
NewsItem('New Blockchain Game Launches', 'https://example.com/blockchain-game'),
NewsItem('Gaming NFTs on the Rise', 'https://example.com/gaming-nfts'),
NewsItem('Play-to-Earn Games Growing', 'https://example.com/play-to-earn'),
],
];
void _onCircleChanged(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Web3 News'),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: _circleNames.map((circleName) {
int index = _circleNames.indexOf(circleName);
return GestureDetector(
onTap: () => _onCircleChanged(index),
child: CircleAvatar(
radius: 16,
backgroundColor: _selectedIndex == index
? Colors.blue
: Colors.grey,
child: Text(
circleName[0].toUpperCase(),
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
);
}).toList(),
),
),
),
body: ListView.builder(
itemCount: _newsItems[_selectedIndex].length,
itemBuilder: (context, index) {
NewsItem newsItem = _newsItems[_selectedIndex][index];
return ListTile(
title: Text(newsItem.title),
subtitle: Text(newsItem.link),
onTap: () {
// Navigate to the news item page
},
);
},
),
);
}
}
class NewsItem {
final String title;
final String link;
NewsItem(this.title, this.link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment