Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 7070de9

Browse files
Fix bootstrap.dart and Android runtime errors (#210)
## Description - In the PR #170 the call to `runApp` was removed. - This PR restores the call while keeping the new `Bloc.observer`. - Also, the Android runtime errors have been removed following the ideas in #195. - Fixes #193 ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ New feature (non-breaking change which adds functionality) - [x] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore
1 parent 721e07f commit 7070de9

File tree

8 files changed

+42
-31
lines changed

8 files changed

+42
-31
lines changed

flutter_nps/lib/bootstrap.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
2424
};
2525

2626
Bloc.observer = AppBlocObserver();
27+
28+
await runZonedGuarded(
29+
() async {
30+
runApp(await builder());
31+
},
32+
(error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
33+
);
2734
}

flutter_nps/lib/capture/view/capture_end_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class CaptureEndView extends StatelessWidget {
3232
const SizedBox(height: Spacing.xl),
3333
Text(
3434
context.l10n.thankYou,
35-
style: Theme.of(context).textTheme.headline5,
35+
style: Theme.of(context).textTheme.headlineSmall,
3636
),
3737
Text(
3838
context.l10n.feedbackSubmittedMessage,
39-
style: Theme.of(context).textTheme.subtitle1,
39+
style: Theme.of(context).textTheme.titleMedium,
4040
),
4141
const SizedBox(height: Spacing.xxhuge),
4242
],

flutter_nps/lib/capture/view/capture_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ class CaptureView extends StatelessWidget {
6060
const SizedBox(height: Spacing.xl),
6161
Text(
6262
context.l10n.captureTitle,
63-
style: theme.textTheme.headline5
63+
style: theme.textTheme.headlineSmall
6464
?.copyWith(fontWeight: FontWeight.bold),
6565
textAlign: TextAlign.center,
6666
),
6767
const SizedBox(height: Spacing.xxs),
6868
Text(
6969
context.l10n.captureMessage,
70-
style: theme.textTheme.subtitle1
70+
style: theme.textTheme.titleMedium
7171
?.copyWith(color: NpsColors.colorGrey2),
7272
),
7373
const SizedBox(height: Spacing.xl),

flutter_nps/packages/app_ui/lib/src/theme/app_theme.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class AppTheme {
2828
),
2929
),
3030
textTheme: const TextTheme(
31-
headline5: NpsStyles.headline5,
32-
subtitle1: NpsStyles.subtitle1,
33-
bodyText2: NpsStyles.link,
31+
headlineSmall: NpsStyles.headline5,
32+
titleMedium: NpsStyles.subtitle1,
33+
bodyMedium: NpsStyles.link,
3434
),
3535
);
3636
}

flutter_nps/packages/app_ui/lib/src/widgets/capture_score_selector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ScoreButton extends StatelessWidget {
6969
alignment: Alignment.center,
7070
),
7171
child: AnimatedDefaultTextStyle(
72-
style: theme.textTheme.subtitle1?.copyWith(
72+
style: theme.textTheme.titleMedium?.copyWith(
7373
color:
7474
isSelected ? NpsColors.colorWhite : NpsColors.colorPrimary1,
7575
) ??

newsfeed_android/app/src/main/java/com/example/newsfeed_android/MainActivity.kt

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.example.newsfeed_android
2+
23
import android.os.Bundle
34
import android.view.Window
45
import androidx.appcompat.app.AppCompatActivity
@@ -39,52 +40,54 @@ class MainActivity : AppCompatActivity() {
3940
val linearLayoutManager = binding.recyclerView.layoutManager as LinearLayoutManager?
4041
if (!isLoading) {
4142
if (linearLayoutManager != null &&
42-
linearLayoutManager.findLastCompletelyVisibleItemPosition() == (rowsArrayList.size - 1)) {
43+
linearLayoutManager.findLastCompletelyVisibleItemPosition() == (rowsArrayList.size - 1)
44+
) {
4345
isLoading = true
44-
loadMore()
46+
loadMore(binding.recyclerView)
4547
}
4648
}
4749
})
4850
binding.recyclerView.addOnScrollListener(loadMoreCallback)
4951
}
5052

51-
private fun initAdapter( binding: ActivityMainBinding) {
53+
private fun initAdapter(binding: ActivityMainBinding) {
5254
recyclerViewAdapter = RecyclerViewAdapter(rowsArrayList)
5355
binding.recyclerView.layoutManager = LinearLayoutManager(applicationContext)
5456
binding.recyclerView.adapter = recyclerViewAdapter
5557
}
5658

57-
private fun populateData(list: ArrayList<String> ) {
59+
private fun populateData(list: ArrayList<String>) {
5860
for (i in 0..20) {
5961
list.add(ROW_ITEM_NAME)
6062
}
6163
}
6264

63-
private fun loadMore() {
64-
if(rowsArrayList.size in 19..29){
65+
private fun loadMore(recyclerView: RecyclerView) {
66+
if (rowsArrayList.size in 19..29) {
6567
runFlutterNPS()
6668
}
6769
runBlocking {
6870
launch {
6971
fakeRequest()
70-
rowsArrayList.removeAt(rowsArrayList.size - 1)
71-
val scrollPosition = rowsArrayList.size
72-
recyclerViewAdapter?.notifyItemRemoved(scrollPosition)
73-
74-
var currentSize = rowsArrayList.size
75-
val nextLimit = currentSize + 10
76-
while (currentSize - 1 < nextLimit) {
77-
rowsArrayList.add(ROW_ITEM_NAME)
78-
currentSize++
72+
recyclerView.post {
73+
rowsArrayList.removeAt(rowsArrayList.size - 1)
74+
val scrollPosition = rowsArrayList.size
75+
recyclerViewAdapter?.notifyItemRemoved(scrollPosition)
76+
77+
var currentSize = rowsArrayList.size
78+
val nextLimit = currentSize + 10
79+
while (currentSize - 1 < nextLimit) {
80+
rowsArrayList.add(ROW_ITEM_NAME)
81+
currentSize++
82+
}
83+
isLoading = false
84+
recyclerViewAdapter?.notifyItemRangeInserted(nextLimit - 10, 10)
7985
}
80-
isLoading = false
81-
recyclerViewAdapter?.notifyItemRangeInserted(nextLimit - 10,10)
8286
}
8387
}
8488
}
8589

8690

87-
8891
private suspend fun fakeRequest(): Boolean {
8992
delay(2000)
9093
return true
@@ -112,7 +115,8 @@ class MainActivity : AppCompatActivity() {
112115
.put(FLUTTER_ENGINE_NAME, flutterEngine)
113116
}
114117

115-
internal class LoadMoreOnScrollListener(private var callback: () -> Unit) : RecyclerView.OnScrollListener() {
118+
internal class LoadMoreOnScrollListener(private var callback: () -> Unit) :
119+
RecyclerView.OnScrollListener() {
116120
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
117121
super.onScrolled(recyclerView, dx, dy)
118122
callback()

newsfeed_android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = '1.6.20-M1'
3+
ext.kotlin_version = '1.6.21'
44
repositories {
55
google()
66
mavenCentral()
@@ -15,8 +15,8 @@ buildscript {
1515

1616
}
1717
dependencies {
18-
classpath "com.android.tools.build:gradle:7.0.3"
19-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
18+
classpath 'com.android.tools.build:gradle:7.4.2'
19+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
2020
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2121

2222
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Feb 03 12:28:34 CET 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)