Created
February 23, 2025 06:13
-
-
Save Lxxyx/5dd85fb6b0e11ffe123d013b9344bddd to your computer and use it in GitHub Desktop.
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(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 NewsPage(), | |
); | |
} | |
} | |
class NewsPage extends StatefulWidget { | |
const NewsPage({super.key}); | |
@override | |
State<NewsPage> createState() => _NewsPageState(); | |
} | |
class _NewsPageState extends State<NewsPage> { | |
int _currentIndex = 0; | |
final List<Community> _communities = [ | |
Community(name: 'Bitcoin', content: [ | |
NewsItem(title: 'Bitcoin Price Surges to $50,000', description: 'Bitcoin price surged to $50,000 today, reaching a new all-time high.'), | |
NewsItem(title: 'Bitcoin Mining Difficulty Reaches New High', description: 'The bitcoin mining difficulty has reached a new high, making it harder for miners to solve complex mathematical equations.'), | |
]), | |
Community(name: 'Ethereum', content: [ | |
NewsItem(title: 'Ethereum 2.0 Launches Successfully', description: 'Ethereum 2.0 has launched successfully, marking a major milestone in the Ethereum network\'s development.'), | |
NewsItem(title: 'Ethereum Gas Fees Reach New High', description: 'Ethereum gas fees have reached a new high, making it more expensive for users to transact on the network.'), | |
]), | |
Community(name: 'Solana', content: [ | |
NewsItem(title: 'Solana Price Rises to $100', description: 'Solana price has risen to $100, reaching a new all-time high.'), | |
NewsItem(title: 'Solana Launches New NFT Marketplace', description: 'Solana has launched a new NFT marketplace, allowing users to buy and sell digital art and collectibles.'), | |
]), | |
]; | |
void _onTabChanged(int index) { | |
setState(() { | |
_currentIndex = index; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Web3 News'), | |
bottom: TabBar( | |
tabs: _communities.map((community) => Tab(text: community.name)).toList(), | |
onTap: _onTabChanged, | |
), | |
), | |
body: TabBarView( | |
children: _communities.map((community) { | |
return ListView.builder( | |
itemCount: community.content.length, | |
itemBuilder: (context, index) { | |
return NewsItemCard(newsItem: community.content[index]); | |
}, | |
); | |
}).toList(), | |
), | |
); | |
} | |
} | |
class Community { | |
final String name; | |
final List<NewsItem> content; | |
Community({required this.name, required this.content}); | |
} | |
class NewsItem { | |
final String title; | |
final String description; | |
NewsItem({required this.title, required this.description}); | |
} | |
class NewsItemCard extends StatelessWidget { | |
final NewsItem newsItem; | |
NewsItemCard({required this.newsItem}); | |
@override | |
Widget build(BuildContext context) { | |
return Card( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
Text( | |
newsItem.title, | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
Text( | |
newsItem.description, | |
style: Theme.of(context).textTheme.bodyText2, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment