Created
February 23, 2025 06:14
-
-
Save Lxxyx/5bce45a18a0c3b56c6d4bd610264b237 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.indigo, | |
), | |
home: const NewsPage(), | |
); | |
} | |
} | |
class NewsPage extends StatefulWidget { | |
const NewsPage({super.key}); | |
@override | |
State<NewsPage> createState() => _NewsPageState(); | |
} | |
class _NewsPageState extends State<NewsPage> { | |
int _currentIndex = 0; | |
List<Community> _communities = [ | |
Community(name: 'Blockchain', content: 'Blockchain news'), | |
Community(name: 'DeFi', content: 'DeFi news'), | |
Community(name: 'NFT', content: 'NFT news'), | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Web3 News'), | |
bottom: TabBar( | |
onTap: (index) { | |
setState(() { | |
_currentIndex = index; | |
}); | |
}, | |
tabs: _communities.map((community) => Tab(text: community.name)).toList(), | |
), | |
), | |
body: GridView.count( | |
crossAxisCount: 2, | |
childAspectRatio: 3, | |
children: _communities[_currentIndex].newsItems, | |
), | |
); | |
} | |
} | |
class Community { | |
final String name; | |
final String content; | |
final List<NewsItem> newsItems; | |
Community({required this.name, required this.content, newsItems}) | |
: newsItems = newsItems ?? [ | |
NewsItem(title: 'News 1', content: 'This is news 1'), | |
NewsItem(title: 'News 2', content: 'This is news 2'), | |
NewsItem(title: 'News 3', content: 'This is news 3'), | |
]; | |
} | |
class NewsItem { | |
final String title; | |
final String content; | |
NewsItem({required this.title, required this.content}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment