-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update fwe samples (pt2 of 3) - Resubmission #13196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Miscellaneous | ||
| *.class | ||
| *.log | ||
| *.pyc | ||
| *.swp | ||
| .DS_Store | ||
| .atom/ | ||
| .build/ | ||
| .buildlog/ | ||
| .history | ||
| .svn/ | ||
| .swiftpm/ | ||
| migrate_working_dir/ | ||
|
|
||
| # IntelliJ related | ||
| *.iml | ||
| *.ipr | ||
| *.iws | ||
| .idea/ | ||
|
|
||
| # The .vscode folder contains launch configuration and tasks you configure in | ||
| # VS Code which you may wish to be included in version control, so this line | ||
| # is commented out by default. | ||
| #.vscode/ | ||
|
|
||
| # Flutter/Dart/Pub related | ||
| **/doc/api/ | ||
| **/ios/Flutter/.last_build_id | ||
| .dart_tool/ | ||
| .flutter-plugins-dependencies | ||
| .pub-cache/ | ||
| .pub/ | ||
| /build/ | ||
| /coverage/ | ||
|
|
||
| # Symbolication related | ||
| app.*.symbols | ||
|
|
||
| # Obfuscation related | ||
| app.*.map.json | ||
|
|
||
| # Android Studio will place build artifacts here | ||
| /android/app/debug | ||
| /android/app/profile | ||
| /android/app/release |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this file. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # This file tracks properties of this Flutter project. | ||
| # Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
| # | ||
| # This file should be version controlled and should not be manually edited. | ||
|
|
||
| version: | ||
| revision: "e308d690a1193ea0d93d62aad6efe48e5994bc3c" | ||
| channel: "[user-branch]" | ||
|
|
||
| project_type: app | ||
|
|
||
| # Tracks metadata for the flutter migrate command | ||
| migration: | ||
| platforms: | ||
| - platform: root | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: android | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: ios | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: linux | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: macos | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: web | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| - platform: windows | ||
| create_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
| base_revision: e308d690a1193ea0d93d62aad6efe48e5994bc3c | ||
|
|
||
| # User provided section | ||
|
|
||
| # List of Local paths (relative to this file) that should be | ||
| # ignored by the migrate tool. | ||
| # | ||
| # Files that are not part of the templates will be ignored by default. | ||
| unmanaged_files: | ||
| - 'lib/main.dart' | ||
| - 'ios/Runner.xcodeproj/project.pbxproj' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # wikipedia_reader | ||
|
|
||
| A new Flutter project. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this file. We have a shared analysis config at the root of the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include: package:flutter_lints/flutter.yaml |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,167 @@ | ||||||||||
| // ignore_for_file: avoid_dynamic_calls | ||||||||||
|
|
||||||||||
| import 'dart:convert'; | ||||||||||
|
Comment on lines
+1
to
+3
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ignore shouldn't be needed. I don't see any code that would trigger it.
Suggested change
|
||||||||||
| import 'dart:io'; | ||||||||||
|
|
||||||||||
| import 'package:flutter/material.dart'; | ||||||||||
| import 'package:http/http.dart'; | ||||||||||
|
|
||||||||||
| import 'summary.dart'; | ||||||||||
|
|
||||||||||
| void main() { | ||||||||||
| runApp(const MainApp()); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class MainApp extends StatelessWidget { | ||||||||||
| const MainApp({super.key}); | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| Widget build(BuildContext context) { | ||||||||||
| return const MaterialApp(home: ArticleView()); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class ArticleModel { | ||||||||||
| Future<Summary> getRandomArticleSummary() async { | ||||||||||
| final uri = Uri.https( | ||||||||||
| 'en.wikipedia.org', | ||||||||||
| '/api/rest_v1/page/random/summary', | ||||||||||
| ); | ||||||||||
| final response = await get(uri); | ||||||||||
|
|
||||||||||
| if (response.statusCode != 200) { | ||||||||||
| throw const HttpException('Failed to update resource'); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return Summary.fromJson(jsonDecode(response.body) as Map<String, Object?>); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class ArticleViewModel extends ChangeNotifier { | ||||||||||
| ArticleViewModel(this.model); | ||||||||||
| final ArticleModel model; | ||||||||||
|
|
||||||||||
| Summary? summary; | ||||||||||
|
|
||||||||||
| bool isLoading = false; | ||||||||||
|
|
||||||||||
| Exception? error; | ||||||||||
|
|
||||||||||
| Future<void> fetchArticle() async { | ||||||||||
| isLoading = true; | ||||||||||
| error = null; | ||||||||||
| notifyListeners(); | ||||||||||
|
|
||||||||||
| try { | ||||||||||
| summary = await model.getRandomArticleSummary(); | ||||||||||
| error = null; | ||||||||||
| } on Exception catch (e) { | ||||||||||
| error = e; | ||||||||||
| } finally { | ||||||||||
| isLoading = false; | ||||||||||
| notifyListeners(); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class ArticleView extends StatefulWidget { | ||||||||||
| const ArticleView({super.key}); | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| State<ArticleView> createState() => _ArticleViewState(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class _ArticleViewState extends State<ArticleView> { | ||||||||||
| late final ArticleViewModel viewModel; | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| void initState() { | ||||||||||
| super.initState(); | ||||||||||
| viewModel = ArticleViewModel(ArticleModel()); | ||||||||||
| viewModel.fetchArticle(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| Widget build(BuildContext context) { | ||||||||||
| return Scaffold( | ||||||||||
| appBar: AppBar(title: const Text('Wikipedia Flutter')), | ||||||||||
| body: Center( | ||||||||||
| child: ListenableBuilder( | ||||||||||
| listenable: viewModel, | ||||||||||
| builder: (context, _) { | ||||||||||
| return switch (( | ||||||||||
| viewModel.isLoading, | ||||||||||
| viewModel.summary, | ||||||||||
| viewModel.error, | ||||||||||
| )) { | ||||||||||
| (true, _, _) => const CircularProgressIndicator(), | ||||||||||
| (_, final summary?, _) => ArticlePage( | ||||||||||
| summary: summary, | ||||||||||
| nextArticleCallback: viewModel.fetchArticle, | ||||||||||
| ), | ||||||||||
| (_, _, final Exception e) => Text('Error: $e'), | ||||||||||
| _ => const Text('Something went wrong!'), | ||||||||||
| }; | ||||||||||
| }, | ||||||||||
| ), | ||||||||||
| ), | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class ArticlePage extends StatelessWidget { | ||||||||||
| const ArticlePage({ | ||||||||||
| super.key, | ||||||||||
| required this.summary, | ||||||||||
| required this.nextArticleCallback, | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| final Summary summary; | ||||||||||
| final VoidCallback nextArticleCallback; | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| Widget build(BuildContext context) { | ||||||||||
| return SingleChildScrollView( | ||||||||||
| child: Column( | ||||||||||
| children: [ | ||||||||||
| ArticleWidget(summary: summary), | ||||||||||
| ElevatedButton( | ||||||||||
| onPressed: nextArticleCallback, | ||||||||||
| child: const Text('Next random article'), | ||||||||||
| ), | ||||||||||
| ], | ||||||||||
| ), | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| class ArticleWidget extends StatelessWidget { | ||||||||||
| const ArticleWidget({super.key, required this.summary}); | ||||||||||
|
|
||||||||||
| final Summary summary; | ||||||||||
|
|
||||||||||
| @override | ||||||||||
| Widget build(BuildContext context) { | ||||||||||
| return Padding( | ||||||||||
| padding: const EdgeInsets.all(8.0), | ||||||||||
| child: Column( | ||||||||||
| spacing: 10.0, | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
| children: [ | ||||||||||
| if (summary.hasImage) Image.network(summary.originalImage!.source), | ||||||||||
| Text( | ||||||||||
| summary.titles.normalized, | ||||||||||
| overflow: TextOverflow.ellipsis, | ||||||||||
| style: Theme.of(context).textTheme.displaySmall, | ||||||||||
| ), | ||||||||||
| if (summary.description != null) | ||||||||||
| Text( | ||||||||||
| summary.description!, | ||||||||||
| overflow: TextOverflow.ellipsis, | ||||||||||
| style: Theme.of(context).textTheme.bodySmall, | ||||||||||
| ), | ||||||||||
| Text(summary.extract), | ||||||||||
| ], | ||||||||||
| ), | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // ignore_for_file: unused_import | ||
|
|
||
| // #docregion All | ||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:http/http.dart'; | ||
|
|
||
| import 'summary.dart'; | ||
|
|
||
| // #docregion main | ||
| void main() { | ||
| runApp(const MainApp()); | ||
| } | ||
| // #enddocregion main | ||
|
|
||
| // #docregion MainApp | ||
| class MainApp extends StatelessWidget { | ||
| const MainApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| appBar: AppBar(title: const Text('Wikipedia Flutter')), | ||
| body: const Center(child: Text('Loading...')), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| // #enddocregion MainApp | ||
|
|
||
| // #enddocregion All |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // ignore_for_file: unused_import, avoid_dynamic_calls | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:http/http.dart'; | ||
|
|
||
| import 'summary.dart'; | ||
|
|
||
| void main() { | ||
| runApp(const MainApp()); | ||
| } | ||
|
|
||
| class MainApp extends StatelessWidget { | ||
| const MainApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| appBar: AppBar(title: const Text('Wikipedia Flutter')), | ||
| body: const Center(child: Text('Loading...')), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // #docregion ArticleModel | ||
| class ArticleModel { | ||
| Future<Summary> getRandomArticleSummary() async { | ||
| final uri = Uri.https( | ||
| 'en.wikipedia.org', | ||
| '/api/rest_v1/page/random/summary', | ||
| ); | ||
| final response = await get(uri); | ||
|
|
||
| if (response.statusCode != 200) { | ||
| throw HttpException('Failed to update resource'); | ||
| } | ||
|
|
||
| return Summary.fromJson(jsonDecode(response.body) as Map<String, Object?>); | ||
| } | ||
| } | ||
|
|
||
| // #enddocregion ArticleModel |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // ignore_for_file: unused_import | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:http/http.dart'; | ||
|
|
||
| import 'summary.dart'; | ||
|
|
||
| void main() { | ||
| runApp(const MainApp()); | ||
| } | ||
|
|
||
| class MainApp extends StatelessWidget { | ||
| const MainApp({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| appBar: AppBar(title: const Text('Wikipedia Flutter')), | ||
| body: const Center(child: Text('Loading...')), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // #docregion ArticleModel | ||
| class ArticleModel { | ||
| // Properties and methods will be added here. | ||
| } | ||
|
|
||
| // #enddocregion ArticleModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can delete this file. There's a root gitignore that covers these.