Skip to content
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

Restyle migrated to null-safety #19

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="Superhero App"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package com.jideguru.superhero_app

import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity

import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
}
}
class MainActivity: FlutterActivity() {}
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-all.zip
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:superhero_app/providers/app_provider.dart';
import 'package:superhero_app/screens/home.dart';
import 'package:superhero_app/util/const.dart';
import 'package:superhero_app/util/theme_config.dart';


void main() {
runApp(
MultiProvider(
Expand Down Expand Up @@ -35,4 +33,4 @@ class MyApp extends StatelessWidget {
},
);
}
}
}
4 changes: 2 additions & 2 deletions lib/providers/app_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -27,7 +26,8 @@ class AppProvider extends ChangeNotifier {
theme = value;
SharedPreferences.getInstance().then((prefs) {
prefs.setString("theme", c).then((val) {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor:
c == "dark" ? ThemeConfig.darkPrimary : ThemeConfig.lightPrimary,
Expand Down
6 changes: 2 additions & 4 deletions lib/screens/details.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import 'package:superhero_app/podo/heroitem.dart';
Expand Down Expand Up @@ -82,13 +80,13 @@ class _SuperheroDetailsState extends State<SuperheroDetails> {
),
Text(
widget.heroItem.name,
style: textTheme.title,
style: textTheme.headline6,
),
Text(
widget.heroItem.biography.fullName.isEmpty
? widget.heroItem.name
: widget.heroItem.biography.fullName,
style: textTheme.subtitle.copyWith(
style: textTheme.subtitle1.copyWith(
fontWeight: FontWeight.w300,
),
),
Expand Down
29 changes: 13 additions & 16 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:convert';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:superhero_app/podo/heroitem.dart';
Expand All @@ -23,7 +21,7 @@ class _HomeState extends State<Home> {
_loading = true;
});
var url = 'https://akabab.github.io/superhero-api/api/all.json';
var res = await http.get(url);
var res = await http.get(Uri.parse(url));
List decodedJson = jsonDecode(res.body);

int code = res.statusCode;
Expand Down Expand Up @@ -58,12 +56,12 @@ class _HomeState extends State<Home> {
icon: Icon(Icons.search),
onPressed: responseList == null
? null
: (){
showSearch(
context: context,
delegate: HeroSearch(all: responseList),
);
},
: () {
showSearch(
context: context,
delegate: HeroSearch(all: responseList),
);
},
tooltip: "Search",
),
IconButton(
Expand All @@ -80,25 +78,24 @@ class _HomeState extends State<Home> {
),
],
),
body: _loading
? _buildProgressIndicator()
: _buildList(),
body: _loading ? _buildProgressIndicator() : _buildList(),
);
}

_buildProgressIndicator(){
_buildProgressIndicator() {
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).accentColor),
valueColor:
AlwaysStoppedAnimation<Color>(Theme.of(context).accentColor),
),
);
}

_buildList(){
_buildList() {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: ListView.builder(
itemCount: responseList?.length??0,
itemCount: responseList?.length ?? 0,
itemBuilder: (BuildContext context, int index) {
HeroItem heroItem = HeroItem.fromJson(responseList[index]);

Expand Down
6 changes: 3 additions & 3 deletions lib/screens/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class HeroSearch extends SearchDelegate {

var search;

if(query2.isNotEmpty){
search =all.where((hero) => hero['name'].contains(query2)).toList();
}else{
if (query2.isNotEmpty) {
search = all.where((hero) => hero['name'].contains(query2)).toList();
} else {
search = all;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/util/theme_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ThemeConfig {
scaffoldBackgroundColor: lightBG,
appBarTheme: AppBarTheme(
elevation: 0,
backgroundColor: lightBG,
foregroundColor: darkPrimary,
),
);

Expand All @@ -28,6 +30,8 @@ class ThemeConfig {
cursorColor: darkAccent,
appBarTheme: AppBarTheme(
elevation: 0,
backgroundColor: darkBG,
foregroundColor: lightPrimary,
),
);
}
6 changes: 3 additions & 3 deletions lib/widget/superhero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:superhero_app/screens/details.dart';
import 'package:superhero_app/widget/superhero_avatar.dart';

class SuperHero extends StatelessWidget {
HeroItem heroItem;
final HeroItem heroItem;

SuperHero({
Key key,
Expand Down Expand Up @@ -57,13 +57,13 @@ class SuperHero extends StatelessWidget {
children: <Widget>[
Text(
"${heroItem.name}",
style: textTheme.title,
style: textTheme.headline6,
),
Text(
heroItem.biography.fullName.isEmpty
? heroItem.name
: heroItem.biography.fullName,
style: textTheme.subtitle.copyWith(
style: textTheme.subtitle1.copyWith(
fontWeight: FontWeight.w300,
),
),
Expand Down